Skip to content
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

Quote: Rename the align attribute to textAlign #42960

Merged
merged 46 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6edad09
Quote: Rename align attribute to textAlign
carolinan Aug 3, 2022
45a9863
Update deprecated.js
carolinan Aug 4, 2022
746c4fb
Update core__quote__deprecated-2.serialized.html
carolinan Aug 4, 2022
745786e
Merge branch 'trunk' into update/rename-align-attribute
carolinan Oct 4, 2022
976d99f
Add alignments for testing
carolinan Oct 4, 2022
67d16e7
Update fixtures, add align block support to the deprecation
carolinan Oct 5, 2022
11ad22b
Remove left/right/center alignments
carolinan Oct 6, 2022
9112eda
Copy save function to deprecation v4. Combine migrations in deprecati…
carolinan Oct 13, 2022
2def1cc
Merge branch 'trunk' into update/rename-align-attribute
carolinan Dec 30, 2022
ef50128
Merge branch 'trunk' into update/rename-align-attribute
carolinan Feb 1, 2023
5fd2a25
Merge branch 'trunk' into update/rename-align-attribute
carolinan Feb 2, 2023
a8057ff
Merge branch 'trunk' into update/rename-align-attribute
carolinan Feb 23, 2023
757a999
Merge branch 'trunk' into update/rename-align-attribute
carolinan Mar 6, 2023
beb1c9d
Update deprecated.js
carolinan Mar 6, 2023
46a7b01
Merge branch 'trunk' into update/rename-align-attribute
carolinan Mar 14, 2023
686ead6
Merge branch 'trunk' into update/rename-align-attribute
carolinan Apr 12, 2023
6367fe6
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jun 14, 2023
215d6fc
build docs
ntsekouras Jun 16, 2023
51e1813
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jun 19, 2023
547539d
Try removing compose, add isEligible
carolinan Jun 19, 2023
420beba
Update deprecated.js
carolinan Jun 19, 2023
46940c5
Update transforms.native.js.snap
carolinan Jun 19, 2023
2aa7d2e
Update index.native.js
carolinan Jun 20, 2023
ac28077
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jun 26, 2023
fa4566b
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jul 2, 2023
f2f96c5
fix: Paragraphs inherit parent text alignment (#52293)
dcalhoun Jul 7, 2023
48ef842
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jul 14, 2023
844482d
Merge branch 'trunk' into update/rename-align-attribute
carolinan Aug 17, 2023
e1d245a
Fixture for version with align attribute
carolinan Aug 21, 2023
54188a1
Revert the block support change
carolinan Aug 21, 2023
92a9b73
Update supoports in the deprecation
carolinan Aug 21, 2023
f3ef6e7
Merge branch 'trunk' into update/rename-align-attribute
carolinan Sep 27, 2023
8434f65
Try to fix the migration
carolinan Sep 27, 2023
c45e17a
Tests: Remove quote from currentlySupportedBlocks in isContainerRelated
carolinan Oct 2, 2023
6509edd
Merge branch 'trunk' into update/rename-align-attribute
carolinan Oct 2, 2023
ecd78fc
Update migration, apply changes requested during review.
carolinan Oct 10, 2023
e280bac
Merge branch 'trunk' into update/rename-align-attribute
carolinan Nov 20, 2023
f6a6f48
Merge branch 'trunk' into update/rename-align-attribute
carolinan Nov 23, 2023
49d93d5
Merge branch 'trunk' into update/rename-align-attribute
carolinan Nov 27, 2023
79d760c
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jan 3, 2024
57b74b7
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jan 8, 2024
7b1be6f
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jan 9, 2024
6245a17
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jan 12, 2024
1b76aba
Merge branch 'trunk' into update/rename-align-attribute
carolinan Jan 25, 2024
7eae1e8
Merge branch 'trunk' into update/rename-align-attribute
carolinan Feb 14, 2024
737dda7
Merge branch 'trunk' into update/rename-align-attribute
carolinan Feb 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ Give quoted text visual emphasis. "In quoting others, we cite ourselves." — Ju

- **Name:** core/quote
- **Category:** text
- **Supports:** anchor, color (background, gradients, link, text), typography (fontSize, lineHeight)
- **Attributes:** align, citation, value
- **Supports:** align (full, wide), anchor, color (background, gradients, link, text), typography (fontSize, lineHeight)
- **Attributes:** citation, textAlign, value

## Read More

Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/quote/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
"default": "",
"__experimentalRole": "content"
},
"align": {
"textAlign": {
"type": "string"
}
},
"supports": {
"align": [ "wide", "full" ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could help to split out the adoption of align support into a follow-up PR to avoid confusion and draw a clear line between the renaming of the old attribute and the new one.

"anchor": true,
"__experimentalOnEnter": true,
"typography": {
Expand Down
73 changes: 72 additions & 1 deletion packages/block-library/src/quote/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import classnames from 'classnames';
*/
import { createBlock, parseWithAttributeSchema } from '@wordpress/blocks';
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { compose } from '@wordpress/compose';

export const migrateToQuoteV2 = ( attributes ) => {
const { value, ...restAttributes } = attributes;
Expand All @@ -34,6 +35,76 @@ export const migrateToQuoteV2 = ( attributes ) => {
];
};

const TEXT_ALIGN_OPTIONS = [ 'left', 'right', 'center' ];

// Migrate existing text alignment settings to the renamed attribute.
const migrateTextAlign = ( attributes ) => {
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
const { align, ...rest } = attributes;
// Check if there are valid alignments stored in the old attribute
// and assign them to the new attribute name.
return TEXT_ALIGN_OPTIONS.includes( align )
? { ...rest, textAlign: align }
: attributes;
};

// Renamed the 'align' attribute to 'textAlign'.
const v4 = {
attributes: {
carolinan marked this conversation as resolved.
Show resolved Hide resolved
value: {
type: 'string',
source: 'html',
selector: 'blockquote',
multiline: 'p',
default: '',
__experimentalRole: 'content',
},
citation: {
type: 'string',
source: 'html',
selector: 'cite',
default: '',
__experimentalRole: 'content',
},
textAlign: {
type: 'string',
},
},
supports: {
align: [ 'wide', 'full' ],
anchor: true,
__experimentalSlashInserter: true,
typography: {
fontSize: true,
lineHeight: true,
__experimentalFontStyle: true,
__experimentalFontWeight: true,
__experimentalLetterSpacing: true,
__experimentalTextTransform: true,
__experimentalDefaultControls: {
fontSize: true,
fontAppearance: true,
},
},
},
save( { attributes } ) {
const { textAlign, value, citation } = attributes;

const className = classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} );

return (
<blockquote { ...useBlockProps.save( { className } ) }>
<RichText.Content multiline value={ value } />
{ ! RichText.isEmpty( citation ) && (
<RichText.Content tagName="cite" value={ citation } />
) }
</blockquote>
);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this save function should be a snapshot of the state of the save function prior to the changes in this PR. I.e. if we switch this version back to using align for generating has-text-align-${ align }, then it should hopefully get the core__quote__deprecated-2.serialized.html fixture passing again without that fixture needing to be changed.

migrate: compose( migrateToQuoteV2, migrateTextAlign ),
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
};

const v3 = {
attributes: {
value: {
Expand Down Expand Up @@ -239,4 +310,4 @@ const v0 = {
*
* See block-deprecation.md
*/
export default [ v3, v2, v1, v0 ];
export default [ v4, v3, v2, v1, v0 ];
12 changes: 7 additions & 5 deletions packages/block-library/src/quote/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function QuoteEdit( {
className,
style,
} ) {
const { align, citation } = attributes;
const { textAlign, citation } = attributes;

useMigrateOnLoad( attributes, clientId );

Expand All @@ -86,7 +86,7 @@ export default function QuoteEdit( {

const blockProps = useBlockProps( {
className: classNames( className, {
[ `has-text-align-${ align }` ]: align,
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
...( ! isWebPlatform && { style } ),
} );
Expand All @@ -99,9 +99,9 @@ export default function QuoteEdit( {
<>
<BlockControls group="block">
<AlignmentControl
value={ align }
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
Expand Down Expand Up @@ -131,7 +131,9 @@ export default function QuoteEdit( {
createBlock( getDefaultBlockName() )
)
}
{ ...( ! isWebPlatform ? { textAlign: align } : {} ) }
{ ...( ! isWebPlatform
? { textAlign: attributes.textAlign }
: {} ) }
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
/>
) }
</BlockQuotation>
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/quote/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import classNames from 'classnames';
import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { align, citation } = attributes;
const { textAlign, citation } = attributes;

const className = classNames( {
[ `has-text-align-${ align }` ]: align,
[ `has-text-align-${ textAlign }` ]: textAlign,
} );

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- wp:quote {"align":"right"} -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right. The final html should have the new attribute..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is something wrong with the deprecation still. @andrewserong suggested (above) that the fixture files should be unchanged.
I have not manually changed them, I ran the command npm fixtures:regenerate because of the reported test failure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is something wrong with the deprecation still.

Yes, that seems like it might be the case.

@andrewserong suggested (above) that the fixture files should be unchanged.

I think I might have been wrong about that, apologies, I think I might have missed some nuance in earlier reviews. In principle the block markup of this fixture should be unchanged (that is, we'd expect the HTML to be <blockquote class="wp-block-quote has-text-align-right">), but we'd also expect the block attributes in the block comment to have a value for textAlign in the serialized version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is the best person to ping to review the deprecation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could just be me but the adoption of the align block support at the same time as this renaming/deprecation makes it harder to reason about.

That said, I agree, the results of this deprecation fixture aren't correct. As @andrewserong noted, the text align class should still be present and the attribute in the bloc comment delimiter updated to textAlign if it was migrated properly.

Fixing migrateTextAlign, or its wrapping of migrateToQuoteV2, gets this fixture to fail due to the incorrect block attributes.

<blockquote class="wp-block-quote has-text-align-right"><!-- wp:paragraph -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>Testing deprecated quote block...</p>
<!-- /wp:paragraph --><cite>...with a caption</cite></blockquote>
<!-- /wp:quote -->