@wordpress/block-library
Version:
Block library for the WordPress editor.
45 lines (37 loc) • 1.2 kB
JavaScript
import { listItem as icon } from '@wordpress/icons';
import { privateApis } from '@wordpress/block-editor';
import initBlock from '../utils/init-block';
import metadata from './block.json';
import edit from './edit';
import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';
const { name } = metadata;
export { metadata, name };
export const settings = {
icon,
edit,
save,
merge( attributes, attributesToMerge ) {
return {
...attributes,
content: attributes.content + attributesToMerge.content,
};
},
transforms,
[ unlock( privateApis ).requiresWrapperOnCopy ]: true,
__experimentalLabel( attributes, { context } ) {
const { content } = attributes;
const customName = attributes?.metadata?.name;
const hasContent = content?.trim().length > 0;
// In the list view, use the block's content as the label.
// If the content is empty, fall back to the default label.
if ( context === 'list-view' && ( customName || hasContent ) ) {
return customName || content;
}
if ( context === 'breadcrumb' && customName ) {
return customName;
}
},
};
export const init = () => initBlock( { name, metadata, settings } );