-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathform.js
50 lines (45 loc) · 1.11 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
/**
* External dependencies
*/
import { createElement, Component } from 'wp-elements';
import { EditableComponent } from 'wp-blocks';
export default class InlineTextBlockForm extends Component {
bindEditable = ( ref ) => {
this.editable = ref;
}
executeCommand = ( ...args ) => {
this.editable.executeCommand( ...args );
};
render() {
const { api, block, setToolbarState, focusConfig } = this.props;
const splitValue = ( left, right ) => {
api.change( { content: left } );
if ( right ) {
api.appendBlock( {
...block,
content: right
} );
} else {
api.appendBlock();
}
};
return (
<EditableComponent
ref={ this.bindEditable }
content={ block.content }
moveCursorUp={ api.moveCursorUp }
moveCursorDown={ api.moveCursorDown }
splitValue={ splitValue }
mergeWithPrevious={ api.mergeWithPrevious }
remove={ api.remove }
onChange={ ( value ) => api.change( { content: value } ) }
setToolbarState={ setToolbarState }
focusConfig={ focusConfig }
onFocusChange={ api.focus }
onType={ api.unselect }
inline
single
/>
);
}
}