Repository navigation
Heading: Migrate to text-align block support #74383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
b2573a6
28b4965
cfb8c4e
bae9c34
9805557
561dbbf
b6d9458
47d7e07
8789310
76f239d
af6b4f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,11 @@ import { | |
| useBlockProps, | ||
| } from '@wordpress/block-editor'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import migrateTextAlignV2 from '../utils/migrate-text-align'; | ||
|
|
||
| const blockSupports = { | ||
| className: false, | ||
| anchor: true, | ||
|
|
@@ -75,7 +80,9 @@ const v1 = { | |
| }, | ||
| }, | ||
| migrate: ( attributes ) => | ||
| migrateCustomColors( migrateTextAlign( attributes ) ), | ||
| migrateTextAlignV2( | ||
| migrateCustomColors( migrateTextAlign( attributes ) ) | ||
| ), | ||
|
Comment on lines
+83
to
+85
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit late feedback, but do we need to call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I've understood is that if you change the deprecated v1 migrate as follows, the textAlign attributes in --- a/packages/block-library/src/heading/deprecated.js
+++ b/packages/block-library/src/heading/deprecated.js
@@ -79,10 +79,8 @@
- // migrate: ( attributes ) =>
- // migrateTextAlignAttributeToBlockSupport(
- // migrateCustomColors( migrateTextAlign( attributes ) )
- // ),
migrate: ( attributes ) =>
migrateCustomColors( migrateTextAlign( attributes ) ),
save( { attributes } ) {--- a/test/integration/fixtures/blocks/core__heading__deprecated-1.serialized.html
+++ b/test/integration/fixtures/blocks/core__heading__deprecated-1.serialized.html
@@ -1,3 +1,3 @@
-<!-- wp:heading {"level":3,"style":{"typography":{"textAlign":"right"}}} -->
-<h3 class="wp-block-heading has-text-align-right">A picture is worth a thousand words, or so the saying goes</h3>
+<!-- wp:heading {"level":3} -->
+<h3 class="wp-block-heading">A picture is worth a thousand words, or so the saying goes</h3>
<!-- /wp:heading -->PR #73116 is also seeing redevelopment of the deprecated functionality. |
||
| save( { attributes } ) { | ||
| const { align, level, content, textColor, customTextColor } = | ||
| attributes; | ||
|
|
@@ -111,7 +118,9 @@ const v2 = { | |
| }, | ||
| }, | ||
| migrate: ( attributes ) => | ||
| migrateCustomColors( migrateTextAlign( attributes ) ), | ||
| migrateTextAlignV2( | ||
| migrateCustomColors( migrateTextAlign( attributes ) ) | ||
| ), | ||
| save( { attributes } ) { | ||
| const { align, content, customTextColor, level, textColor } = | ||
| attributes; | ||
|
|
@@ -149,7 +158,9 @@ const v3 = { | |
| }, | ||
| }, | ||
| migrate: ( attributes ) => | ||
| migrateCustomColors( migrateTextAlign( attributes ) ), | ||
| migrateTextAlignV2( | ||
| migrateCustomColors( migrateTextAlign( attributes ) ) | ||
| ), | ||
| save( { attributes } ) { | ||
| const { align, content, customTextColor, level, textColor } = | ||
| attributes; | ||
|
|
@@ -195,7 +206,10 @@ const v4 = { | |
| }, | ||
| attributes: blockAttributes, | ||
| isEligible: ( { align } ) => TEXT_ALIGN_OPTIONS.includes( align ), | ||
| migrate: migrateTextAlign, | ||
| migrate: ( attributes ) => | ||
| migrateTextAlignV2( | ||
| migrateCustomColors( migrateTextAlign( attributes ) ) | ||
| ), | ||
| save( { attributes } ) { | ||
| const { align, content, level } = attributes; | ||
| const TagName = 'h' + level; | ||
|
|
@@ -283,8 +297,107 @@ const v5 = { | |
| </TagName> | ||
| ); | ||
| }, | ||
| migrate: ( attributes ) => | ||
| migrateTextAlignV2( | ||
| migrateCustomColors( migrateTextAlign( attributes ) ) | ||
| ), | ||
| }; | ||
|
|
||
| const v6 = { | ||
| supports: { | ||
| align: [ 'wide', 'full' ], | ||
| anchor: true, | ||
| className: true, | ||
| splitting: true, | ||
| __experimentalBorder: { | ||
| color: true, | ||
| radius: true, | ||
| style: true, | ||
| width: true, | ||
| }, | ||
| color: { | ||
| gradients: true, | ||
| link: true, | ||
| __experimentalDefaultControls: { | ||
| background: true, | ||
| text: true, | ||
| }, | ||
| }, | ||
| spacing: { | ||
| margin: true, | ||
| padding: true, | ||
| }, | ||
| typography: { | ||
| fontSize: true, | ||
| lineHeight: true, | ||
| __experimentalFontFamily: true, | ||
| __experimentalFontStyle: true, | ||
| __experimentalFontWeight: true, | ||
| __experimentalLetterSpacing: true, | ||
| __experimentalTextTransform: true, | ||
| __experimentalTextDecoration: true, | ||
| __experimentalWritingMode: true, | ||
| fitText: true, | ||
| __experimentalDefaultControls: { | ||
| fontSize: true, | ||
| }, | ||
| }, | ||
| __unstablePasteTextInline: true, | ||
| __experimentalSlashInserter: true, | ||
| interactivity: { | ||
| clientNavigation: true, | ||
| }, | ||
| }, | ||
| attributes: { | ||
| textAlign: { | ||
| type: 'string', | ||
| }, | ||
| content: { | ||
| type: 'string', | ||
| source: 'html', | ||
| selector: 'h1,h2,h3,h4,h5,h6', | ||
| default: '', | ||
| role: 'content', | ||
| }, | ||
| level: { | ||
| type: 'number', | ||
| default: 2, | ||
| }, | ||
| levelOptions: { | ||
| type: 'array', | ||
| }, | ||
| placeholder: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| save( { attributes } ) { | ||
| const { textAlign, content, level } = attributes; | ||
| const TagName = 'h' + level; | ||
|
|
||
| const className = clsx( { | ||
| [ `has-text-align-${ textAlign }` ]: textAlign, | ||
| } ); | ||
|
|
||
| return ( | ||
| <TagName { ...useBlockProps.save( { className } ) }> | ||
| <RichText.Content value={ content } /> | ||
| </TagName> | ||
| ); | ||
| }, | ||
| migrate: ( attributes ) => | ||
| migrateTextAlignV2( | ||
| migrateCustomColors( migrateTextAlign( attributes ) ) | ||
| ), | ||
| isEligible( attributes ) { | ||
| return ( | ||
| !! attributes.textAlign || | ||
| !! attributes.className?.match( | ||
| /\bhas-text-align-(left|center|right)\b/ | ||
| ) | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| const deprecated = [ v5, v4, v3, v2, v1 ]; | ||
| const deprecated = [ v6, v5, v4, v3, v2, v1 ]; | ||
|
|
||
| export default deprecated; | ||
Uh oh!
There was an error while loading. Please reload this page.