Download wp-calypso/apps/wpcom-block-editor/src/default/features/rich-text.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/wpcom-block-editor/src/default/features/rich-text.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/apps/wpcom-block-editor/src/default/features/rich-text.js
-
curl -L -o rich-text.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/wpcom-block-editor/src/default/features/rich-text.js
1.43 kB
| /* global wpcomGutenberg */ | |
| import { RichTextToolbarButton } from '@wordpress/block-editor'; | |
| import { compose, ifCondition } from '@wordpress/compose'; | |
| import { withSelect, withDispatch } from '@wordpress/data'; | |
| import { registerFormatType } from '@wordpress/rich-text'; | |
| import { get } from 'lodash'; | |
| const RichTextJustifyButton = ( { blockId, isBlockJustified, updateBlockAttributes } ) => { | |
| const onToggle = () => | |
| updateBlockAttributes( blockId, { align: isBlockJustified ? null : 'justify' } ); | |
| return ( | |
| <RichTextToolbarButton | |
| icon="editor-justify" | |
| title={ wpcomGutenberg.richTextToolbar.justify } | |
| onClick={ onToggle } | |
| isActive={ isBlockJustified } | |
| /> | |
| ); | |
| }; | |
| const ConnectedRichTextJustifyButton = compose( | |
| withSelect( ( wpSelect ) => { | |
| const selectedBlock = wpSelect( 'core/block-editor' ).getSelectedBlock(); | |
| if ( ! selectedBlock ) { | |
| return {}; | |
| } | |
| return { | |
| blockId: selectedBlock.clientId, | |
| blockName: selectedBlock.name, | |
| isBlockJustified: 'justify' === get( selectedBlock, 'attributes.align' ), | |
| }; | |
| } ), | |
| withDispatch( ( dispatch ) => ( { | |
| updateBlockAttributes: dispatch( 'core/editor' ).updateBlockAttributes, | |
| } ) ), | |
| ifCondition( ( props ) => 'core/paragraph' === props.blockName ) | |
| )( RichTextJustifyButton ); | |
| registerFormatType( 'wpcom/justify', { | |
| title: wpcomGutenberg.richTextToolbar.justify, | |
| tagName: 'p', | |
| className: null, | |
| edit: ConnectedRichTextJustifyButton, | |
| } ); | |