import { createBlock, getBlockAttributes } from '@wordpress/blocks'; import type { BlockConfiguration } from '@wordpress/blocks'; import metadata from './block.json'; import type { ParagraphAttributes } from './types'; const { name } = metadata; const transforms: BlockConfiguration[ 'transforms' ] = { from: [ { type: 'raw', // Paragraph is a fallback and should be matched last. priority: 20, selector: 'p', schema: ( { phrasingContentSchema, isPaste } ) => ( { p: { children: phrasingContentSchema, attributes: isPaste ? [] : [ 'style', 'id' ], }, } ), transform( node ) { const attributes = getBlockAttributes( name, node.outerHTML ) as ParagraphAttributes; const { textAlign } = ( node as HTMLElement ).style || {}; if ( textAlign === 'left' || textAlign === 'center' || textAlign === 'right' ) { attributes.style = { ...attributes.style, typography: { ...attributes.style?.typography, textAlign, }, }; } return createBlock( name, attributes ); }, }, ], }; export default transforms;