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

TinyMCE per block: Adding a preview button to display the generated HTML #176

Merged
merged 1 commit into from
Mar 3, 2017
Merged
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
10 changes: 5 additions & 5 deletions tinymce-per-block/build/app.js

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions tinymce-per-block/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ class App extends Component {
const type = forceType ? forceType : this.state.activeRenderer;
switch ( type ) {
case 'block':
const html = serializers.block.serialize(
nextContent.map( block => {
const blockDefinition = getBlock( block.blockType );
return blockDefinition.serialize( block );
} )
);
this.setState( {
content: {
block: nextContent,
html: serializers.block.serialize(
nextContent.map( block => {
const blockDefinition = getBlock( block.blockType );
return blockDefinition.serialize( block );
} )
)
raw: html,
html
}
} );
return;
Expand All @@ -50,16 +52,17 @@ class App extends Component {
return parsedBlock ? parsedBlock : getBlock( 'text' ).parse( rawBlock );
} )
.map( block => Object.assign( { uid: uniqueId() }, block ) ),
html: nextContent
html: nextContent,
raw: nextContent
}
} );
return;
}
}

toggleRenderer = () => {
selectRenderer = ( renderer ) => () => {
this.setState( {
activeRenderer: this.state.activeRenderer === 'block' ? 'html' : 'block'
activeRenderer: renderer
} );
}

Expand All @@ -72,7 +75,11 @@ class App extends Component {
const Renderer = renderers[ activeRenderer ];
return (
<div className="renderers">
<button className="toggle-renderer" onClick={ this.toggleRenderer }>Html/Block</button>
<div className="toggle-renderer">
<button onClick={ this.selectRenderer( 'block' ) }>Block</button>
<button onClick={ this.selectRenderer( 'html' ) }>Html</button>
<button onClick={ this.selectRenderer( 'raw' ) }>Preview</button>
</div>
<div className={ `renderer-${ activeRenderer }` }>
<Renderer content={ content[ activeRenderer ] } onChange={ this.updateParsedContent } />
</div>
Expand Down
1 change: 1 addition & 0 deletions tinymce-per-block/src/renderers/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as block } from './block';
export { default as html } from './html';
export { default as raw } from './raw';
10 changes: 10 additions & 0 deletions tinymce-per-block/src/renderers/raw/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* External dependencies
*/
import { createElement } from 'wp-elements';

export default function RawRenderer( { content } ) {
return (
<div dangerouslySetInnerHTML={ { __html: content } } />
);
}