-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
index.js
42 lines (34 loc) · 1.04 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
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { withFilters } from '@wordpress/components';
/**
* Internal dependencies
*/
import {
getBlockType,
getBlockDefaultClassname,
hasBlockSupport,
} from '../api';
export function BlockEdit( props ) {
const { name, attributes = {} } = props;
const blockType = getBlockType( name );
if ( ! blockType ) {
return null;
}
// Generate a class name for the block's editable form
const generatedClassName = hasBlockSupport( blockType, 'className', true ) ?
getBlockDefaultClassname( name ) :
null;
const className = classnames( generatedClassName, attributes.className );
// `edit` and `save` are functions or components describing the markup
// with which a block is displayed. If `blockType` is valid, assign
// them preferencially as the render value for the block.
const Edit = blockType.edit || blockType.save;
return <Edit { ...props } className={ className } />;
}
export default withFilters( 'blocks.BlockEdit' )( BlockEdit );