diff --git a/packages/block-library/src/paragraph/deprecated.js b/packages/block-library/src/paragraph/deprecated.js
new file mode 100644
index 00000000000000..c3f18db62d62c3
--- /dev/null
+++ b/packages/block-library/src/paragraph/deprecated.js
@@ -0,0 +1,168 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+import { isFinite, omit } from 'lodash';
+
+/**
+ * WordPress dependencies
+ */
+import {
+ RawHTML,
+} from '@wordpress/element';
+import {
+ getColorClassName,
+ RichText,
+} from '@wordpress/block-editor';
+
+const supports = {
+ className: false,
+};
+
+const blockAttributes = {
+ align: {
+ type: 'string',
+ },
+ content: {
+ type: 'string',
+ source: 'html',
+ selector: 'p',
+ default: '',
+ },
+ dropCap: {
+ type: 'boolean',
+ default: false,
+ },
+ placeholder: {
+ type: 'string',
+ },
+ textColor: {
+ type: 'string',
+ },
+ customTextColor: {
+ type: 'string',
+ },
+ backgroundColor: {
+ type: 'string',
+ },
+ customBackgroundColor: {
+ type: 'string',
+ },
+ fontSize: {
+ type: 'string',
+ },
+ customFontSize: {
+ type: 'number',
+ },
+ direction: {
+ type: 'string',
+ enum: [ 'ltr', 'rtl' ],
+ },
+};
+
+const deprecated = [
+ {
+ supports,
+ attributes: {
+ ...blockAttributes,
+ width: {
+ type: 'string',
+ },
+ },
+ save( { attributes } ) {
+ const {
+ width,
+ align,
+ content,
+ dropCap,
+ backgroundColor,
+ textColor,
+ customBackgroundColor,
+ customTextColor,
+ fontSize,
+ customFontSize,
+ } = attributes;
+
+ const textClass = getColorClassName( 'color', textColor );
+ const backgroundClass = getColorClassName( 'background-color', backgroundColor );
+ const fontSizeClass = fontSize && `is-${ fontSize }-text`;
+
+ const className = classnames( {
+ [ `align${ width }` ]: width,
+ 'has-background': backgroundColor || customBackgroundColor,
+ 'has-drop-cap': dropCap,
+ [ fontSizeClass ]: fontSizeClass,
+ [ textClass ]: textClass,
+ [ backgroundClass ]: backgroundClass,
+ } );
+
+ const styles = {
+ backgroundColor: backgroundClass ? undefined : customBackgroundColor,
+ color: textClass ? undefined : customTextColor,
+ fontSize: fontSizeClass ? undefined : customFontSize,
+ textAlign: align,
+ };
+
+ return (
+
{ content }
; + }, + migrate( attributes ) { + return omit( { + ...attributes, + customFontSize: isFinite( attributes.fontSize ) ? attributes.fontSize : undefined, + customTextColor: attributes.textColor && '#' === attributes.textColor[ 0 ] ? attributes.textColor : undefined, + customBackgroundColor: attributes.backgroundColor && '#' === attributes.backgroundColor[ 0 ] ? attributes.backgroundColor : undefined, + }, [ 'fontSize', 'textColor', 'backgroundColor' ] ); + }, + }, + { + supports, + attributes: { + ...blockAttributes, + content: { + type: 'string', + source: 'html', + default: '', + }, + }, + save( { attributes } ) { + return{ content }
; - }, - migrate( attributes ) { - return omit( { - ...attributes, - customFontSize: isFinite( attributes.fontSize ) ? attributes.fontSize : undefined, - customTextColor: attributes.textColor && '#' === attributes.textColor[ 0 ] ? attributes.textColor : undefined, - customBackgroundColor: attributes.backgroundColor && '#' === attributes.backgroundColor[ 0 ] ? attributes.backgroundColor : undefined, - }, [ 'fontSize', 'textColor', 'backgroundColor' ] ); - }, - }, - { - supports, - attributes: { - ...schema, - content: { - type: 'string', - source: 'html', - default: '', - }, - }, - save( { attributes } ) { - return++ ); + }, + }, { + attributes: { + ...blockAttributes, + citation: { + type: 'string', + source: 'html', + selector: 'footer', + }, + align: { + type: 'string', + default: 'none', + }, + }, + + save( { attributes } ) { + const { value, citation, align } = attributes; + + return ( ++ { ! RichText.isEmpty( citation ) && } +
++ ); + }, + }, +]; + +export default deprecated; diff --git a/packages/block-library/src/pullquote/index.js b/packages/block-library/src/pullquote/index.js index 0c7c29b38ac670..944f7562385b5b 100644 --- a/packages/block-library/src/pullquote/index.js +++ b/packages/block-library/src/pullquote/index.js @@ -2,18 +2,18 @@ * WordPress dependencies */ import { __, _x } from '@wordpress/i18n'; -import { RichText } from '@wordpress/block-editor'; /** * Internal dependencies */ import { SOLID_COLOR_STYLE_NAME } from './shared'; +import deprecated from './deprecated'; import edit from './edit'; import icon from './icon'; import metadata from './block.json'; import save from './save'; -const { name, attributes: blockAttributes } = metadata; +const { name } = metadata; export { metadata, name }; @@ -30,42 +30,5 @@ export const settings = { }, edit, save, - deprecated: [ { - attributes: { - ...blockAttributes, - }, - save( { attributes } ) { - const { value, citation } = attributes; - return ( -+ { ! RichText.isEmpty( citation ) && } +
-- ); - }, - }, { - attributes: { - ...blockAttributes, - citation: { - type: 'string', - source: 'html', - selector: 'footer', - }, - align: { - type: 'string', - default: 'none', - }, - }, - - save( { attributes } ) { - const { value, citation, align } = attributes; - - return ( -- { ! RichText.isEmpty( citation ) && } -
-- ); - }, - } ], + deprecated, }; diff --git a/packages/block-library/src/quote/deprecated.js b/packages/block-library/src/quote/deprecated.js new file mode 100644 index 00000000000000..61024ff336aed1 --- /dev/null +++ b/packages/block-library/src/quote/deprecated.js @@ -0,0 +1,96 @@ +/** + * External dependencies + */ +import { omit } from 'lodash'; + +/** + * WordPress dependencies + */ +import { RichText } from '@wordpress/block-editor'; + +const blockAttributes = { + value: { + type: 'string', + source: 'html', + selector: 'blockquote', + multiline: 'p', + default: '', + }, + citation: { + type: 'string', + source: 'html', + selector: 'cite', + default: '', + }, + align: { + type: 'string', + }, +}; + +const deprecated = [ + { + attributes: { + ...blockAttributes, + style: { + type: 'number', + default: 1, + }, + }, + + migrate( attributes ) { + if ( attributes.style === 2 ) { + return { + ...omit( attributes, [ 'style' ] ), + className: attributes.className ? attributes.className + ' is-style-large' : 'is-style-large', + }; + } + + return attributes; + }, + + save( { attributes } ) { + const { align, value, citation, style } = attributes; + + return ( +- { ! RichText.isEmpty( citation ) && } -
++ ); + }, + }, + { + attributes: { + ...blockAttributes, + citation: { + type: 'string', + source: 'html', + selector: 'footer', + default: '', + }, + style: { + type: 'number', + default: 1, + }, + }, + + save( { attributes } ) { + const { align, value, citation, style } = attributes; + + return ( ++ { ! RichText.isEmpty( citation ) && } +
++ ); + }, + }, +]; + +export default deprecated; diff --git a/packages/block-library/src/quote/index.js b/packages/block-library/src/quote/index.js index 105bde9dde68bc..806b8597411cca 100644 --- a/packages/block-library/src/quote/index.js +++ b/packages/block-library/src/quote/index.js @@ -1,24 +1,19 @@ -/** - * External dependencies - */ -import { omit } from 'lodash'; - /** * WordPress dependencies */ import { __, _x } from '@wordpress/i18n'; -import { RichText } from '@wordpress/block-editor'; /** * Internal dependencies */ +import deprecated from './deprecated'; import edit from './edit'; import icon from './icon'; import metadata from './block.json'; import save from './save'; import transforms from './transforms'; -const { name, attributes: blockAttributes } = metadata; +const { name } = metadata; export { metadata, name }; @@ -48,69 +43,5 @@ export const settings = { citation: attributes.citation + citation, }; }, - deprecated: [ - { - attributes: { - ...blockAttributes, - style: { - type: 'number', - default: 1, - }, - }, - - migrate( attributes ) { - if ( attributes.style === 2 ) { - return { - ...omit( attributes, [ 'style' ] ), - className: attributes.className ? attributes.className + ' is-style-large' : 'is-style-large', - }; - } - - return attributes; - }, - - save( { attributes } ) { - const { align, value, citation, style } = attributes; - - return ( -+ { ! RichText.isEmpty( citation ) && } +
-- ); - }, - }, - { - attributes: { - ...blockAttributes, - citation: { - type: 'string', - source: 'html', - selector: 'footer', - default: '', - }, - style: { - type: 'number', - default: 1, - }, - }, - - save( { attributes } ) { - const { align, value, citation, style } = attributes; - - return ( -- { ! RichText.isEmpty( citation ) && } -
-- ); - }, - }, - ], + deprecated, };- { ! RichText.isEmpty( citation ) && } -