Skip to content

Commit

Permalink
Add deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Aug 5, 2023
1 parent 974ef4e commit 8e2c68a
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
87 changes: 84 additions & 3 deletions packages/block-library/src/list/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { RichText, InnerBlocks, useBlockProps } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import migrateFontFamily from '../utils/migrate-font-family';
import { migrateToListV2 } from './utils';
import { migrateToListV2, migrateTypeToInlineStyle } from './utils';

const v0 = {
attributes: {
Expand Down Expand Up @@ -138,6 +138,87 @@ const v1 = {
migrate: migrateToListV2,
};

// In #53301 changed to use the inline style instead of type attribute.
const v2 = {
attributes: {
ordered: {
type: 'boolean',
default: false,
__experimentalRole: 'content',
},
values: {
type: 'string',
source: 'html',
selector: 'ol,ul',
multiline: 'li',
__unstableMultilineWrapperTags: [ 'ol', 'ul' ],
default: '',
__experimentalRole: 'content',
},
type: {
type: 'string',
},
start: {
type: 'number',
},
reversed: {
type: 'boolean',
},
placeholder: {
type: 'string',
},
},
supports: {
anchor: true,
className: false,
typography: {
fontSize: true,
lineHeight: true,
__experimentalFontFamily: true,
__experimentalFontWeight: true,
__experimentalFontStyle: true,
__experimentalTextTransform: true,
__experimentalTextDecoration: true,
__experimentalLetterSpacing: true,
__experimentalDefaultControls: {
fontSize: true,
},
},
color: {
gradients: true,
link: true,
__experimentalDefaultControls: {
background: true,
text: true,
},
},
spacing: {
margin: true,
padding: true,
__experimentalDefaultControls: {
margin: false,
padding: false,
},
},
__unstablePasteTextInline: true,
__experimentalSelector: 'ol,ul',
__experimentalSlashInserter: true,
},
isEligible( { type } ) {
return type && type !== '1';
},
save( { attributes } ) {
const { ordered, type, reversed, start } = attributes;
const TagName = ordered ? 'ol' : 'ul';
return (
<TagName { ...useBlockProps.save( { type, reversed, start } ) }>
<InnerBlocks.Content />
</TagName>
);
},
migrate: migrateTypeToInlineStyle,
};

/**
* New deprecations need to be placed first
* for them to have higher priority.
Expand All @@ -146,4 +227,4 @@ const v1 = {
*
* See block-deprecation.md
*/
export default [ v1, v0 ];
export default [ v2, v1, v0 ];
20 changes: 20 additions & 0 deletions packages/block-library/src/list/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,23 @@ export function migrateToListV2( attributes ) {
listBlock.innerBlocks,
];
}

export function migrateTypeToInlineStyle( attributes ) {
const typeStyles = {
A: 'upper-alpha',
a: 'lower-alpha',
I: 'upper-roman',
i: 'lower-roman',
};

const { type } = attributes;

if ( typeStyles[ type ] ) {
return {
...attributes,
type: typeStyles[ type ],
};
}

return attributes;
}

0 comments on commit 8e2c68a

Please sign in to comment.