-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
59 lines (49 loc) · 1.12 KB
/
index.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
/**
* Internal dependencies
*/
import { registerBlock, createBlock, query } from '../../api';
import Editable from '../../editable';
const { children } = query;
registerBlock( 'core/text', {
title: wp.i18n.__( 'Text' ),
icon: 'text',
category: 'common',
attributes: {
content: children(),
},
defaultAttributes: {
content: <p />,
},
merge( attributes, attributesToMerge ) {
return {
content: wp.element.concatChildren( attributes.content, attributesToMerge.content ),
};
},
edit( { attributes, setAttributes, insertBlockAfter, focus, setFocus, mergeBlocks } ) {
const { content } = attributes;
return (
<Editable
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
} );
} }
focus={ focus }
onFocus={ setFocus }
onSplit={ ( before, after ) => {
setAttributes( { content: before } );
insertBlockAfter( createBlock( 'core/text', {
content: after,
} ) );
} }
onMerge={ mergeBlocks }
showAlignments
/>
);
},
save( { attributes } ) {
const { content } = attributes;
return content;
},
} );