UNPKG

@wordpress/block-library

Version:
79 lines (68 loc) 1.84 kB
/** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { paragraph as icon } from '@wordpress/icons'; import { privateApis as blocksPrivateApis } from '@wordpress/blocks'; /** * Internal dependencies */ import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; import save from './save'; import transforms from './transforms'; import variations from './variations'; import { unlock } from '../lock-unlock'; const { fieldsKey, formKey } = unlock( blocksPrivateApis ); const { name } = metadata; export { metadata, name }; export const settings = { icon, example: { attributes: { content: __( 'In a village of La Mancha, the name of which I have no desire to call to mind, there lived not long since one of those gentlemen that keep a lance in the lance-rack, an old buckler, a lean hack, and a greyhound for coursing.' ), }, }, __experimentalLabel( attributes, { context } ) { const customName = attributes?.metadata?.name; if ( context === 'list-view' && customName ) { return customName; } if ( context === 'accessibility' ) { if ( customName ) { return customName; } const { content } = attributes; return ! content || content.length === 0 ? __( 'Empty' ) : content; } }, transforms, deprecated, merge( attributes, attributesToMerge ) { return { content: ( attributes.content || '' ) + ( attributesToMerge.content || '' ), }; }, edit, save, variations, }; if ( window.__experimentalContentOnlyInspectorFields ) { settings[ fieldsKey ] = [ { id: 'content', label: __( 'Content' ), type: 'richtext', }, ]; settings[ formKey ] = { fields: [ 'content' ], }; } export const init = () => initBlock( { name, metadata, settings } );