-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.js
42 lines (37 loc) · 933 Bytes
/
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
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { removeFormat, slice } from '@wordpress/rich-text';
import { RichTextToolbarButton } from '@wordpress/block-editor';
import { help } from '@wordpress/icons';
const name = 'core/unknown';
const title = __( 'Clear Unknown Formatting' );
export const unknown = {
name,
title,
tagName: '*',
className: null,
edit( { isActive, value, onChange, onFocus } ) {
function onClick() {
onChange( removeFormat( value, name ) );
onFocus();
}
const selectedValue = slice( value );
const hasUnknownFormats = selectedValue.formats.some( ( formats ) => {
return formats.some( ( format ) => format.type === name );
} );
if ( ! isActive && ! hasUnknownFormats ) {
return null;
}
return (
<RichTextToolbarButton
name="unknown"
icon={ help }
title={ title }
onClick={ onClick }
isActive={ true }
/>
);
},
};