-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
85 lines (77 loc) · 1.92 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Internal dependencies
*/
import './style.scss';
import { registerBlock, query as hpq } from 'api';
import Editable from 'components/editable';
const { children, prop, query } = hpq;
registerBlock( 'core/list', {
title: wp.i18n.__( 'List' ),
icon: 'editor-ul',
category: 'common',
attributes: {
nodeName: prop( 'ol,ul', 'nodeName' ),
items: query( 'li', {
value: children()
} )
},
controls: [
{
icon: 'editor-alignleft',
title: wp.i18n.__( 'Align left' ),
isActive: ( { align } ) => ! align || 'left' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: undefined } );
}
},
{
icon: 'editor-aligncenter',
title: wp.i18n.__( 'Align center' ),
isActive: ( { align } ) => 'center' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: 'center' } );
}
},
{
icon: 'editor-alignright',
title: wp.i18n.__( 'Align right' ),
isActive: ( { align } ) => 'right' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: 'right' } );
}
},
{
icon: 'editor-justify',
title: wp.i18n.__( 'Justify' ),
isActive: ( { align } ) => 'justify' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: 'justify' } );
}
}
],
edit( { attributes, focus, setFocus } ) {
const { nodeName = 'OL', items = [], align } = attributes;
const content = items.map( ( item, i ) => {
return <li key={ i }>{ item.value }</li>;
} );
return (
<Editable
tagName={ nodeName.toLowerCase() }
style={ align ? { textAlign: align } : null }
value={ content }
focus={ focus }
onFocus={ setFocus }
className="blocks-list" />
);
},
save( { attributes } ) {
const { nodeName = 'OL', items = [] } = attributes;
return wp.element.createElement(
nodeName.toLowerCase(),
null,
items.map( ( item, index ) => (
<li key={ index }>{ item.value }</li>
) )
);
}
} );