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

Try: Use amp-mathml and amp-fit-text components in Gutenberg block edit function's React components #1342

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions assets/css/amp-editor-blocks.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.is-amp-fit-text + .blocks-font-size > .components-font-size-picker__custom-input {
display: none;
}
.edit-post-visual-editor amp-fit-text p {
font-size: inherit;
}
23 changes: 19 additions & 4 deletions assets/js/amp-editor-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars
var attributes = props.attributes,
name = props.name,
ampLayout,
inspectorControls;
inspectorControls,
WrappedBlockEdit;

ampLayout = attributes.ampLayout;

Expand Down Expand Up @@ -324,11 +325,25 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars
];
}

WrappedBlockEdit = el( BlockEdit, _.extend( {
key: 'original'
}, props ) );

if ( -1 !== component.data.textBlocks.indexOf( name ) && props.attributes.ampFitText ) {
WrappedBlockEdit = el(
'amp-fit-text',
{
'min-font-size': props.attributes.minFont,
'max-font-size': props.attributes.maxFont,
height: props.attributes.height
},
WrappedBlockEdit
);
}

return [
inspectorControls,
el( BlockEdit, _.extend( {
key: 'original'
}, props ) )
WrappedBlockEdit
];
};
};
Expand Down
21 changes: 12 additions & 9 deletions blocks/amp-mathml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ export default registerBlockType(
}
},

edit( { attributes, setAttributes } ) {
edit( { attributes, isSelected, setAttributes } ) {
const { dataFormula } = attributes;

return (
<PlainText
key='formula'
value={ dataFormula }
placeholder={ __( 'Insert formula', 'amp' ) }
onChange={ ( value ) => setAttributes( { dataFormula: value } ) }
/>
);
if ( isSelected ) {
return (
<PlainText
key='formula'
value={ dataFormula }
placeholder={ __( 'Insert formula', 'amp' ) }
onChange={ ( value ) => setAttributes( { dataFormula: value } ) }
/>
);
}
return <amp-mathml layout="container" data-formula={ dataFormula }></amp-mathml>;
},

save( { attributes } ) {
Expand Down
3 changes: 3 additions & 0 deletions includes/admin/class-amp-editor-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public function enqueue_block_editor_assets() {
array( 'wp-blocks', 'lodash', 'wp-i18n', 'wp-element', 'wp-components' ),
AMP__VERSION
);

wp_enqueue_script( 'amp-mathml' );
wp_enqueue_script( 'amp-fit-text' );
}

wp_enqueue_script(
Expand Down