/** * External dependencies */ import clsx from 'clsx'; /** * WordPress dependencies */ import { RichText, useBlockProps, // @ts-ignore: has no exported member __experimentalGetElementClassName, // @ts-ignore: has no exported member __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles, // @ts-ignore: has no exported member __experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles, } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import type { BlockEditProps } from '@wordpress/blocks'; /** * Internal dependencies */ import type { BlockAttributes } from './types'; export default function BlockEditPreview( { attributes }: BlockEditProps< BlockAttributes > ) { const { url, alt, caption, align, width, height, aspectRatio, scale, enableResponsiveImageSources: sources, } = attributes; const borderProps = getBorderClassesAndStyles( attributes ); const shadowProps = typeof getShadowClassesAndStyles === 'function' ? getShadowClassesAndStyles( attributes ) : {}; const filteredSources = sources.filter( ( { srcset, mediaType, mediaValue } ) => { return srcset && mediaType && mediaValue; } ); const classes = clsx( { [ `align${ align }` ]: align, 'has-custom-border': !! borderProps.className || ( borderProps.style && Object.keys( borderProps.style ).length > 0 ), } ); const blockProps = useBlockProps( { className: classes, } ); return (
{ filteredSources.length > 0 && filteredSources.map( ( { srcset, mediaType, mediaValue }, index ) => ( ) ) } { { ! RichText.isEmpty( caption ) && ( ) }
); }