import type { BlockDeprecation, BlockSupports } from '@wordpress/blocks'; import migrateFontFamily from '../utils/migrate-font-family'; import migrateTextAlign from '../utils/migrate-text-align'; import type { PostTitleAttributes } from './types'; const v2: BlockDeprecation< PostTitleAttributes > = { attributes: { textAlign: { type: 'string', }, level: { type: 'number', default: 2, }, levelOptions: { type: 'array', }, isLink: { type: 'boolean', default: false, }, rel: { type: 'string', attribute: 'rel', default: '', }, linkTarget: { type: 'string', default: '_self', }, }, supports: { anchor: true, align: [ 'wide', 'full' ], html: false, color: { gradients: true, link: true, __experimentalDefaultControls: { background: true, text: true, link: true, }, }, spacing: { padding: true, margin: true, }, typography: { fontSize: true, lineHeight: true, __experimentalFontFamily: true, __experimentalTextTransform: true, __experimentalTextDecoration: true, __experimentalFontStyle: true, __experimentalFontWeight: true, __experimentalLetterSpacing: true, __experimentalDefaultControls: { fontSize: true, }, }, interactivity: { clientNavigation: true, }, __experimentalBorder: { radius: true, color: true, width: true, style: true, __experimentalDefaultControls: { radius: true, color: true, width: true, style: true, }, }, } as BlockSupports, migrate: ( attributes ) => migrateTextAlign( attributes ) as PostTitleAttributes, isEligible( attributes ) { return ( !! attributes.textAlign || !! ( attributes.className as string | undefined )?.match( /\bhas-text-align-(left|center|right)\b/ ) ); }, save: () => null, }; const v1: BlockDeprecation< PostTitleAttributes > = { attributes: { textAlign: { type: 'string', }, level: { type: 'number', default: 2, }, isLink: { type: 'boolean', default: false, }, rel: { type: 'string', attribute: 'rel', default: '', }, linkTarget: { type: 'string', default: '_self', }, }, supports: { align: [ 'wide', 'full' ], html: false, color: { gradients: true, link: true, }, spacing: { margin: true, }, typography: { fontSize: true, lineHeight: true, __experimentalFontFamily: true, __experimentalFontWeight: true, __experimentalFontStyle: true, __experimentalTextTransform: true, }, } as BlockSupports, save() { return null; }, migrate: ( attributes ) => migrateFontFamily( attributes ) as PostTitleAttributes, isEligible( attributes ) { return !! ( attributes as PostTitleAttributes ).style?.typography ?.fontFamily; }, }; /** * New deprecations need to be placed first * for them to have higher priority. * * Old deprecations may need to be updated as well. * * See block-deprecation.md */ export default [ v2, v1 ];