-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Framework: Handle and upgrade deprecated blocks #3665
Changes from all commits
06fe513
3863e50
3f94460
bd6f99c
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.wp-block-quote.blocks-quote-style-1 { | ||
.wp-block-quote:not(.is-large) { | ||
border-left: 4px solid $black; | ||
padding-left: 1em; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* External dependencies | ||
*/ | ||
import { isString, get } from 'lodash'; | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
|
@@ -26,36 +27,38 @@ const fromEditableValue = value => value.map( ( subValue ) => ( { | |
children: subValue, | ||
} ) ); | ||
|
||
const blockAttributes = { | ||
value: { | ||
type: 'array', | ||
source: 'query', | ||
selector: 'blockquote > p', | ||
query: { | ||
children: { | ||
source: 'node', | ||
}, | ||
}, | ||
default: [], | ||
}, | ||
citation: { | ||
type: 'array', | ||
source: 'children', | ||
selector: 'cite', | ||
}, | ||
align: { | ||
type: 'string', | ||
}, | ||
style: { | ||
type: 'number', | ||
default: 1, | ||
}, | ||
}; | ||
|
||
registerBlockType( 'core/quote', { | ||
title: __( 'Quote' ), | ||
icon: 'format-quote', | ||
category: 'common', | ||
|
||
attributes: { | ||
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. Why move this away? 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.
To address this, it's because the deprecated and original versions share most of the same attributes, with deprecated assigning into to reflect the original attributes behavior of citation. 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. I have concerns with block looking different at first sight when you open one to learn from, that i think we should minimize. |
||
value: { | ||
type: 'array', | ||
source: 'query', | ||
selector: 'blockquote > p', | ||
query: { | ||
children: { | ||
source: 'node', | ||
}, | ||
}, | ||
default: [], | ||
}, | ||
citation: { | ||
type: 'array', | ||
source: 'children', | ||
selector: 'footer', | ||
}, | ||
align: { | ||
type: 'string', | ||
}, | ||
style: { | ||
type: 'number', | ||
default: 1, | ||
}, | ||
}, | ||
attributes: blockAttributes, | ||
|
||
transforms: { | ||
from: [ | ||
|
@@ -152,6 +155,7 @@ registerBlockType( 'core/quote', { | |
edit( { attributes, setAttributes, focus, setFocus, mergeBlocks, className } ) { | ||
const { align, value, citation, style } = attributes; | ||
const focusedEditable = focus ? focus.editable || 'value' : null; | ||
const containerClassname = classnames( className, style === 2 ? 'is-large' : '' ); | ||
|
||
return [ | ||
focus && ( | ||
|
@@ -181,7 +185,7 @@ registerBlockType( 'core/quote', { | |
), | ||
<blockquote | ||
key="quote" | ||
className={ `${ className } blocks-quote-style-${ style }` } | ||
className={ containerClassname } | ||
> | ||
<Editable | ||
multiline="p" | ||
|
@@ -220,16 +224,47 @@ registerBlockType( 'core/quote', { | |
|
||
return ( | ||
<blockquote | ||
className={ `blocks-quote-style-${ style }` } | ||
className={ style === 2 ? 'is-large' : '' } | ||
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. I think we could use 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. mmm, this means the value of the attribute can change between two versions, I'm going to introduce a 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. Mmm, can it be handled in the attribute itself as a fallback? 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. We might want to sit on it a bit otherwise. 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. No, we can't :(. Adding it is not so complex though 5dd81ce 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. Let's extract that commit into a separate PR so we can discuss the migration of values in isolation. |
||
style={ { textAlign: align ? align : null } } | ||
> | ||
{ value.map( ( paragraph, i ) => ( | ||
<p key={ i }>{ paragraph.children && paragraph.children.props.children }</p> | ||
) ) } | ||
{ citation && citation.length > 0 && ( | ||
<footer>{ citation }</footer> | ||
<cite>{ citation }</cite> | ||
) } | ||
</blockquote> | ||
); | ||
}, | ||
|
||
deprecated: [ | ||
{ | ||
attributes: { | ||
...blockAttributes, | ||
citation: { | ||
type: 'array', | ||
source: 'children', | ||
selector: 'footer', | ||
}, | ||
}, | ||
|
||
save( { attributes } ) { | ||
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. I have a slight concern with accumulating 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 about the "attributes"? do you think we should share common attributes or maybe fine to duplicate? |
||
const { align, value, citation, style } = attributes; | ||
|
||
return ( | ||
<blockquote | ||
className={ `blocks-quote-style-${ style }` } | ||
style={ { textAlign: align ? align : null } } | ||
> | ||
{ value.map( ( paragraph, i ) => ( | ||
<p key={ i }>{ paragraph.children && paragraph.children.props.children }</p> | ||
) ) } | ||
{ citation && citation.length > 0 && ( | ||
<footer>{ citation }</footer> | ||
) } | ||
</blockquote> | ||
); | ||
}, | ||
}, | ||
], | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
font-style: normal; | ||
} | ||
|
||
&.blocks-quote-style-2 { | ||
&.is-large { | ||
padding: 0 1em; | ||
p { | ||
font-size: 24px; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:core/quote {"style":"1"} --> | ||
<blockquote class="wp-block-quote blocks-quote-style-1"><p>The editor will endeavour to create a new page and post building experience that makes writing rich posts effortless, and has “blocks” to make it easy what today might take shortcodes, custom HTML, or “mystery meat” embed discovery.</p><footer>Matt Mullenweg, 2017</footer></blockquote> | ||
<blockquote class="wp-block-quote"><p>The editor will endeavour to create a new page and post building experience that makes writing rich posts effortless, and has “blocks” to make it easy what today might take shortcodes, custom HTML, or “mystery meat” embed discovery.</p><cite>Matt Mullenweg, 2017</cite></blockquote> | ||
<!-- /wp:core/quote --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<!-- wp:quote --> | ||
<blockquote class="wp-block-quote blocks-quote-style-1"> | ||
<p>The editor will endeavour to create a new page and post building experience that makes writing rich posts effortless, and has “blocks” to make it easy what today might take shortcodes, custom HTML, or “mystery meat” embed discovery.</p> | ||
<footer>Matt Mullenweg, 2017</footer> | ||
</blockquote> | ||
<blockquote class="wp-block-quote"> | ||
<p>The editor will endeavour to create a new page and post building experience that makes writing rich posts effortless, and has “blocks” to make it easy what today might take shortcodes, custom HTML, or “mystery meat” embed discovery.</p><cite>Matt Mullenweg, 2017</cite></blockquote> | ||
<!-- /wp:quote --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:core/quote {"style":"2"} --> | ||
<blockquote class="wp-block-quote blocks-quote-style-2"><p>There is no greater agony than bearing an untold story inside you.</p><footer>Maya Angelou</footer></blockquote> | ||
<blockquote class="wp-block-quote is-large"><p>There is no greater agony than bearing an untold story inside you.</p><cite>Maya Angelou</cite></blockquote> | ||
<!-- /wp:core/quote --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: I had a similar need for validation tests, wondering if we ought to put the effort into a generalized "expect console errors" assertion:
gutenberg/blocks/api/test/validation.js
Lines 33 to 43 in 9bfd837
Maybe
expect( console ).toHaveLogged( 'error' );
set up intest/unit/setup-test-framework.js
?https://facebook.github.io/jest/docs/en/expect.html#expectextendmatchers
cc @gziolo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea! We are spying already on console warn and error methods: https://github.com/WordPress/gutenberg/blob/master/test/unit/setup-test-framework.js#L25. It should be easy to inplement 👍