-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d46596
commit c989bce
Showing
4 changed files
with
172 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Fragment } from '@wordpress/element'; | ||
import { | ||
BlockControls, | ||
AlignmentToolbar, | ||
RichText, | ||
} from '@wordpress/editor'; | ||
|
||
export default function edit( { attributes, setAttributes, isSelected, mergeBlocks, onReplace, className } ) { | ||
const { align, value, citation } = attributes; | ||
return ( | ||
<Fragment> | ||
<BlockControls> | ||
<AlignmentToolbar | ||
value={ align } | ||
onChange={ ( nextAlign ) => { | ||
setAttributes( { align: nextAlign } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
<blockquote className={ className } style={ { textAlign: align } }> | ||
<RichText | ||
multiline | ||
value={ value } | ||
onChange={ | ||
( nextValue ) => setAttributes( { | ||
value: nextValue, | ||
} ) | ||
} | ||
onMerge={ mergeBlocks } | ||
onRemove={ ( forward ) => { | ||
const hasEmptyCitation = ! citation || citation.length === 0; | ||
if ( ! forward && hasEmptyCitation ) { | ||
onReplace( [] ); | ||
} | ||
} } | ||
/* translators: the text of the quotation */ | ||
placeholder={ __( 'Write quote…' ) } | ||
/> | ||
{ ( ! RichText.isEmpty( citation ) || isSelected ) && ( | ||
<RichText | ||
value={ citation } | ||
onChange={ | ||
( nextCitation ) => setAttributes( { | ||
citation: nextCitation, | ||
} ) | ||
} | ||
/* translators: the individual or entity quoted */ | ||
placeholder={ __( 'Write citation…' ) } | ||
className="wp-block-quote__citation" | ||
/> | ||
) } | ||
</blockquote> | ||
</Fragment> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Component } from '@wordpress/element'; | ||
import { parse } from '@wordpress/blocks'; | ||
import { RichText } from '@wordpress/editor'; | ||
|
||
const minHeight = 50; | ||
|
||
class QuoteEdit extends Component { | ||
render() { | ||
const { | ||
attributes, | ||
setAttributes, | ||
style, | ||
mergeBlocks, | ||
onReplace, | ||
isSelected, | ||
} = this.props; | ||
|
||
const { | ||
placeholder, | ||
align, | ||
value, | ||
citation, | ||
} = attributes; | ||
|
||
return ( | ||
<View style={ { textAlign: align } }> | ||
<RichText | ||
tagName="blockquote" | ||
multiline | ||
value={ value } | ||
style={ { | ||
...style, | ||
minHeight: Math.max( minHeight, typeof attributes.aztecHeight === 'undefined' ? 0 : attributes.aztecHeight ), | ||
} } | ||
onChange={ ( event ) => { | ||
// Create a React Tree from the new HTML | ||
const newQuoteBlock = parse( '<!-- wp:quote --><blockquote class="wp-block-quote">' + event.content + '</blockquote><!-- /wp:quote -->' )[ 0 ]; | ||
setAttributes( { | ||
...this.props.attributes, | ||
value: newQuoteBlock.attributes.value, | ||
} ); | ||
} | ||
} | ||
onContentSizeChange={ ( event ) => { | ||
setAttributes( { | ||
...this.props.attributes, | ||
aztecHeight: event.aztecHeight, | ||
} ); | ||
} | ||
} | ||
onMerge={ mergeBlocks } | ||
onRemove={ ( forward ) => { | ||
const hasEmptyCitation = ! citation || citation.length === 0; | ||
if ( ! forward && hasEmptyCitation ) { | ||
onReplace( [] ); | ||
} | ||
} } | ||
/* translators: the text of the quotation */ | ||
placeholder={ placeholder || __( 'Write quote…' ) } | ||
/> | ||
{ ( ! RichText.isEmpty( citation ) || isSelected ) && ( | ||
<RichText | ||
tagName="cite" | ||
style={ { | ||
...style, | ||
minHeight: Math.max( minHeight, typeof attributes.aztecHeight === 'undefined' ? 0 : attributes.aztecHeight ), | ||
} } | ||
value={ citation } | ||
onChange={ | ||
( event ) => { | ||
// TODO: remove this fix | ||
const openingTagRegexp = RegExp( '<cite>', 'gim' ); | ||
const closingTagRegexp = RegExp( '</cite>', 'gim' ); | ||
let newCiteVaule = event.content; | ||
newCiteVaule = newCiteVaule.replace( openingTagRegexp, '' ).replace( closingTagRegexp, '' ); | ||
setAttributes( { | ||
...this.props.attributes, | ||
citation: newCiteVaule, | ||
} ); | ||
} | ||
} | ||
onContentSizeChange={ ( event ) => { | ||
setAttributes( { | ||
...this.props.attributes, | ||
aztecHeight: event.aztecHeight, | ||
} ); | ||
} | ||
} | ||
/* translators: the individual or entity quoted */ | ||
placeholder={ placeholder || __( 'Write citation…' ) } | ||
className="wp-block-quote__citation" | ||
/> | ||
) } | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default QuoteEdit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters