From a11d823c6600c1f8253420933627ad9e7b27bfd9 Mon Sep 17 00:00:00 2001 From: Derek Blank Date: Tue, 25 Jul 2023 11:45:40 +1000 Subject: [PATCH] Allow soft returns for native Verse block --- .../block-library/src/verse/edit.native.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 packages/block-library/src/verse/edit.native.js diff --git a/packages/block-library/src/verse/edit.native.js b/packages/block-library/src/verse/edit.native.js new file mode 100644 index 0000000000000..f8451dda8f095 --- /dev/null +++ b/packages/block-library/src/verse/edit.native.js @@ -0,0 +1,70 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { + RichText, + BlockControls, + AlignmentToolbar, + useBlockProps, +} from '@wordpress/block-editor'; +import { createBlock, getDefaultBlockName } from '@wordpress/blocks'; + +export default function VerseEdit( { + attributes, + setAttributes, + mergeBlocks, + onRemove, + style, + insertBlocksAfter, +} ) { + const { textAlign, content } = attributes; + const blockProps = useBlockProps( { + className: classnames( { + [ `has-text-align-${ textAlign }` ]: textAlign, + } ), + style, + } ); + + return ( + <> + + { + setAttributes( { textAlign: nextAlign } ); + } } + /> + + { + setAttributes( { + content: nextContent, + } ); + } } + aria-label={ __( 'Verse text' ) } + placeholder={ __( 'Write verseā€¦' ) } + onRemove={ onRemove } + multiline={ true } + blurOnSubmit={ true } + onMerge={ mergeBlocks } + textAlign={ textAlign } + textAlignVertical={ 'top' } + { ...blockProps } + __unstablePastePlainText + __unstableOnSplitAtEnd={ () => + insertBlocksAfter( createBlock( getDefaultBlockName() ) ) + } + /> + + ); +}