Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -655,8 +655,8 @@ The author name. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/pac

- **Name:** core/post-author-name
- **Category:** theme
- **Supports:** anchor, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** isLink, linkTarget, textAlign
- **Supports:** anchor, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight, textAlign), ~~html~~
- **Attributes:** isLink, linkTarget

## Comment (deprecated)

Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/post-author-name/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"description": "The author name.",
"textdomain": "default",
"attributes": {
"textAlign": {
"type": "string"
},
"isLink": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -44,6 +41,7 @@
"typography": {
"fontSize": true,
"lineHeight": true,
"textAlign": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
Expand Down
78 changes: 78 additions & 0 deletions packages/block-library/src/post-author-name/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Internal dependencies
*/
import migrateTextAlign from '../utils/migrate-text-align';

const v1 = {
attributes: {
isLink: {
type: 'boolean',
default: false,
role: 'content',
},
linkTarget: {
type: 'string',
default: '_self',
role: 'content',
},
textAlign: {
type: 'string',
},
},
supports: {
anchor: true,
html: false,
spacing: {
margin: true,
padding: true,
},
color: {
gradients: true,
link: true,
__experimentalDefaultControls: {
background: true,
text: true,
},
},
typography: {
fontSize: true,
lineHeight: true,
__experimentalFontFamily: true,
__experimentalFontWeight: true,
__experimentalFontStyle: true,
__experimentalTextTransform: true,
__experimentalTextDecoration: 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,
},
},
},
migrate: migrateTextAlign,
isEligible( attributes ) {
return (
!! attributes.textAlign ||
!! attributes.className?.match(
/\bhas-text-align-(left|center|right)\b/
)
);
},
save: () => null,
};

export default [ v1 ];
43 changes: 14 additions & 29 deletions packages/block-library/src/post-author-name/edit.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
import {
AlignmentControl,
BlockControls,
InspectorControls,
useBlockProps,
} from '@wordpress/block-editor';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';
Expand All @@ -26,11 +16,18 @@ import {
*/
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

function PostAuthorNameEdit( {
context: { postType, postId },
attributes: { textAlign, isLink, linkTarget },
setAttributes,
} ) {
/**
* Internal dependencies
*/
import useDeprecatedTextAlign from '../utils/deprecated-text-align-attributes';

function PostAuthorNameEdit( props ) {
useDeprecatedTextAlign( props );
const {
attributes: { isLink, linkTarget },
setAttributes,
context: { postType, postId },
} = props;
const { authorName, supportsAuthor } = useSelect(
( select ) => {
const { getEditedEntityRecord, getUser, getPostType } =
Expand All @@ -50,11 +47,7 @@ function PostAuthorNameEdit( {
[ postType, postId ]
);

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

const displayName = authorName?.name || __( 'Author Name' );

Expand All @@ -74,14 +67,6 @@ function PostAuthorNameEdit( {

return (
<>
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<InspectorControls>
<ToolsPanel
label={ __( 'Settings' ) }
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/post-author-name/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { postAuthor as icon } from '@wordpress/icons';
import initBlock from '../utils/init-block';
import metadata from './block.json';
import edit from './edit';
import deprecated from './deprecated';
import transforms from './transforms';

const { name } = metadata;
Expand All @@ -18,6 +19,7 @@ export const settings = {
icon,
transforms,
edit,
deprecated,
};

export const init = () => initBlock( { name, metadata, settings } );
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- wp:post-author-name {"textAlign":"left"} /-->

<!-- wp:post-author-name {"textAlign":"center"} /-->

<!-- wp:post-author-name {"textAlign":"right"} /-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"name": "core/post-author-name",
"isValid": true,
"attributes": {
"isLink": false,
"linkTarget": "_self",
"style": {
"typography": {
"textAlign": "left"
}
}
},
"innerBlocks": []
},
{
"name": "core/post-author-name",
"isValid": true,
"attributes": {
"isLink": false,
"linkTarget": "_self",
"style": {
"typography": {
"textAlign": "center"
}
}
},
"innerBlocks": []
},
{
"name": "core/post-author-name",
"isValid": true,
"attributes": {
"isLink": false,
"linkTarget": "_self",
"style": {
"typography": {
"textAlign": "right"
}
}
},
"innerBlocks": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
{
"blockName": "core/post-author-name",
"attrs": {
"textAlign": "left"
},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n\n",
"innerContent": [ "\n\n" ]
},
{
"blockName": "core/post-author-name",
"attrs": {
"textAlign": "center"
},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n\n",
"innerContent": [ "\n\n" ]
},
{
"blockName": "core/post-author-name",
"attrs": {
"textAlign": "right"
},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- wp:post-author-name {"style":{"typography":{"textAlign":"left"}}} /-->

<!-- wp:post-author-name {"style":{"typography":{"textAlign":"center"}}} /-->

<!-- wp:post-author-name {"style":{"typography":{"textAlign":"right"}}} /-->
Loading