-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathform.js
80 lines (72 loc) · 2.21 KB
/
form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* External dependencies
*/
import { createElement, Component } from 'wp-elements';
import { EditableComponent } from 'wp-blocks';
import AlignmentToolbar from 'controls/alignment-toolbar';
import EditableFormatToolbar from 'controls/editable-format-toolbar';
import BlockArrangement from 'controls/block-arrangement';
export default class HtmlBlockForm extends Component {
bindEditable = ( ref ) => {
this.editable = ref;
}
setAlignment = ( align ) => {
this.props.api.change( { align } );
};
bindFormatToolbar = ( ref ) => {
this.toolbar = ref;
};
setToolbarState = ( ...args ) => {
this.toolbar && this.toolbar.setToolbarState( ...args );
};
render() {
const { api, block, isSelected, first, last, focusConfig } = this.props;
const splitValue = ( left, right ) => {
api.change( { content: left } );
if ( right ) {
api.appendBlock( {
...block,
content: right
} );
} else {
api.appendBlock();
}
};
const selectedTextAlign = block.align || 'left';
const style = {
textAlign: selectedTextAlign
};
return (
<div>
{ isSelected && <BlockArrangement first={ first } last={ last }
moveBlockUp={ api.moveBlockUp } moveBlockDown={ api.moveBlockDown } /> }
{ isSelected && (
<div className="block-list__block-controls">
<div className="block-list__block-controls-group">
<AlignmentToolbar value={ selectedTextAlign } onChange={ this.setAlignment } />
</div>
<div className="block-list__block-controls-group">
<EditableFormatToolbar editable={ this.editable } ref={ this.bindFormatToolbar } />
</div>
</div>
) }
<div className="html-block__form" style={ style } onClick={ api.select }>
<EditableComponent
ref={ this.bindEditable }
content={ block.content }
moveCursorUp={ api.moveCursorUp }
moveCursorDown={ api.moveCursorDown }
splitValue={ splitValue }
mergeWithPrevious={ api.mergeWithPrevious }
remove={ api.remove }
setToolbarState={ this.setToolbarState }
onChange={ ( value ) => api.change( { content: value } ) }
focusConfig={ focusConfig }
onFocusChange={ api.focus }
onType={ api.unselect }
/>
</div>
</div>
);
}
}