1 |
|
2 |
|
3 |
|
4 | import HeadingToolbar from './heading-toolbar';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import { View } from 'react-native';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | import { __ } from '@wordpress/i18n';
|
15 | import { Component } from '@wordpress/element';
|
16 | import { RichText, BlockControls } from '@wordpress/block-editor';
|
17 | import { createBlock } from '@wordpress/blocks';
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | import './editor.scss';
|
23 |
|
24 | const minHeight = 24;
|
25 |
|
26 | class HeadingEdit extends Component {
|
27 | constructor( props ) {
|
28 | super( props );
|
29 |
|
30 | this.state = {
|
31 | aztecHeight: 0,
|
32 | };
|
33 | }
|
34 |
|
35 | render() {
|
36 | const {
|
37 | attributes,
|
38 | setAttributes,
|
39 | mergeBlocks,
|
40 | insertBlocksAfter,
|
41 | } = this.props;
|
42 |
|
43 | const {
|
44 | level,
|
45 | placeholder,
|
46 | content,
|
47 | } = attributes;
|
48 |
|
49 | const tagName = 'h' + level;
|
50 | return (
|
51 | <View>
|
52 | <BlockControls>
|
53 | <HeadingToolbar minLevel={ 2 } maxLevel={ 5 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />
|
54 | </BlockControls>
|
55 | <RichText
|
56 | tagName={ tagName }
|
57 | value={ content }
|
58 | isSelected={ this.props.isSelected }
|
59 | onFocus={ this.props.onFocus }
|
60 | onBlur={ this.props.onBlur }
|
61 | onCaretVerticalPositionChange={ this.props.onCaretVerticalPositionChange }
|
62 | style={ {
|
63 | minHeight: Math.max( minHeight, this.state.aztecHeight ),
|
64 | } }
|
65 | onChange={ ( value ) => setAttributes( { content: value } ) }
|
66 | onMerge={ mergeBlocks }
|
67 | onSplit={
|
68 | insertBlocksAfter ?
|
69 | ( before, after, ...blocks ) => {
|
70 | setAttributes( { content: before } );
|
71 | insertBlocksAfter( [
|
72 | ...blocks,
|
73 | createBlock( 'core/paragraph', { content: after } ),
|
74 | ] );
|
75 | } :
|
76 | undefined
|
77 | }
|
78 | onContentSizeChange={ ( event ) => {
|
79 | this.setState( { aztecHeight: event.aztecHeight } );
|
80 | } }
|
81 | placeholder={ placeholder || __( 'Write heading…' ) }
|
82 | />
|
83 | </View>
|
84 | );
|
85 | }
|
86 | }
|
87 | export default HeadingEdit;
|