Skip to content

Commit

Permalink
Move heading block transforms to before edit and save
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed Apr 20, 2017
1 parent 285bab6 commit 1aed21a
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions blocks/library/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,6 @@ registerBlock( 'core/heading', {
} ) )
],

edit( { attributes, setAttributes } ) {
const { content, tag, align } = attributes;

return (
<Editable
tagName={ tag }
value={ content }
onChange={ ( value ) => setAttributes( { content: value } ) }
style={ align ? { textAlign: align } : null }
/>
);
},

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

return (
<Tag
style={ align ? { textAlign: align } : null }
dangerouslySetInnerHTML={ { __html: content } } />
);
},

transforms: {
from: [
{
Expand All @@ -68,10 +45,10 @@ registerBlock( 'core/heading', {
return {
tag: 'H2',
content,
align
align,
};
}
}
},
},
],
to: [
{
Expand All @@ -80,10 +57,33 @@ registerBlock( 'core/heading', {
transform: ( { content, align } ) => {
return {
content: [ content ],
align
align,
};
}
}
},
},
]
}
},

edit( { attributes, setAttributes } ) {
const { content, tag, align } = attributes;

return (
<Editable
tagName={ tag }
value={ content }
onChange={ ( value ) => setAttributes( { content: value } ) }
style={ align ? { textAlign: align } : null }
/>
);
},

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

return (
<Tag
style={ align ? { textAlign: align } : null }
dangerouslySetInnerHTML={ { __html: content } } />
);
},
} );

0 comments on commit 1aed21a

Please sign in to comment.