-
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.
TinyMCE per block: Switch Text and HTML blocks making the HTML the fa…
…llback block (#180)
- Loading branch information
1 parent
0c0b767
commit 33fc659
Showing
15 changed files
with
207 additions
and
188 deletions.
There are no files selected for viewing
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
8 changes: 4 additions & 4 deletions
8
...ck/src/blocks/paragraph-block/_style.scss → ...r-block/src/blocks/html-block/_style.scss
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,13 +1,13 @@ | ||
.paragraph-block__form { | ||
width: 100%; | ||
border: none; | ||
.html-block__form { | ||
margin: 0; | ||
outline: none; | ||
font: inherit; | ||
font-family: "Merriweather", serif; | ||
font-size: 16px; | ||
color: inherit; | ||
font-weight: 300; | ||
p { | ||
padding: 0; | ||
margin: 0; | ||
margin-top: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement, Component } from 'wp-elements'; | ||
|
||
import { EditableComponent } from 'wp-blocks'; | ||
import AlignmentToolbar from 'controls/alignment-toolbar'; | ||
import EditableFormatToolbar from 'controls/editable-format-toolbar'; | ||
import BlockArrangement from 'controls/block-arrangement'; | ||
|
||
export default class HtmlBlockForm extends Component { | ||
merge = ( block, index ) => { | ||
const acceptedBlockTypes = [ 'html', 'quote', 'text', 'heading' ]; | ||
if ( acceptedBlockTypes.indexOf( block.blockType ) === -1 ) { | ||
return; | ||
} | ||
|
||
const { block: { content }, remove, change } = this.props; | ||
remove( index ); | ||
setTimeout( () => change( { content: content + block.content } ) ); | ||
setTimeout( () => this.editable.updateContent() ); | ||
} | ||
|
||
bindEditable = ( ref ) => { | ||
this.editable = ref; | ||
} | ||
|
||
setAlignment = ( align ) => { | ||
this.props.change( { align } ); | ||
}; | ||
|
||
bindFormatToolbar = ( ref ) => { | ||
this.toolbar = ref; | ||
}; | ||
|
||
setToolbarState = ( ...args ) => { | ||
this.toolbar && this.toolbar.setToolbarState( ...args ); | ||
}; | ||
|
||
render() { | ||
const { block, isFocused, change, moveUp, moveDown, appendBlock, | ||
mergeWithPrevious, remove, focusConfig, focus } = this.props; | ||
const splitValue = ( left, right ) => { | ||
change( { content: left } ); | ||
if ( right ) { | ||
appendBlock( { | ||
...block, | ||
content: right | ||
} ); | ||
} else { | ||
appendBlock(); | ||
} | ||
}; | ||
const selectedTextAlign = block.align || 'left'; | ||
const style = { | ||
textAlign: selectedTextAlign | ||
}; | ||
|
||
return ( | ||
<div> | ||
{ isFocused && <BlockArrangement block={ block } /> } | ||
{ isFocused && ( | ||
<div className="block-list__block-controls"> | ||
<div className="block-list__block-controls-group"> | ||
<AlignmentToolbar value={ selectedTextAlign } onChange={ this.setAlignment } /> | ||
</div> | ||
|
||
<div className="block-list__block-controls-group"> | ||
<EditableFormatToolbar editable={ this.editable } ref={ this.bindFormatToolbar } /> | ||
</div> | ||
</div> | ||
) } | ||
<div className="html-block__form" style={ style }> | ||
<EditableComponent | ||
ref={ this.bindEditable } | ||
content={ block.content } | ||
moveUp={ moveUp } | ||
moveDown={ moveDown } | ||
splitValue={ splitValue } | ||
mergeWithPrevious={ mergeWithPrevious } | ||
remove={ remove } | ||
setToolbarState={ this.setToolbarState } | ||
onChange={ ( value ) => change( { content: value } ) } | ||
focusConfig={ focusConfig } | ||
onFocusChange={ focus } | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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,30 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlock } from 'wp-blocks'; | ||
import { EditorTableIcon } from 'dashicons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import form from './form'; | ||
|
||
registerBlock( 'html', { | ||
title: 'HTML', | ||
form: form, | ||
icon: EditorTableIcon, | ||
parse: ( rawBlock ) => { | ||
return { | ||
blockType: 'html', | ||
align: rawBlock.attrs.align || 'no-align', | ||
content: rawBlock.rawContent, | ||
}; | ||
}, | ||
serialize: ( block ) => { | ||
return { | ||
blockType: 'html', | ||
attrs: { /* align: block.align */ }, | ||
rawContent: block.content | ||
}; | ||
} | ||
} ); |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
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,13 +1,13 @@ | ||
.text-block__form { | ||
margin: 0; | ||
outline: none; | ||
width: 100%; | ||
border: none; | ||
font: inherit; | ||
font-family: "Merriweather", serif; | ||
font-size: 16px; | ||
color: inherit; | ||
font-weight: 300; | ||
p { | ||
padding: 0; | ||
margin-top: 0; | ||
margin: 0; | ||
} | ||
} |
Oops, something went wrong.