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

Add wrapper in Query block and align support #30804

Merged
merged 4 commits into from
Apr 28, 2021
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
20 changes: 14 additions & 6 deletions lib/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true}} -->
<div class="wp-block-query">
<!-- wp:query-loop -->
<!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-featured-image {"isLink":true,"align":"wide"} /-->
Expand All @@ -25,6 +26,7 @@
<!-- /wp:separator -->
<!-- wp:post-date /-->
<!-- /wp:query-loop -->
</div>
<!-- /wp:query -->',
)
);
Expand All @@ -36,6 +38,7 @@
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true}} -->
<div class="wp-block-query">
<!-- wp:query-loop -->
<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"66.66%"} -->
Expand All @@ -47,6 +50,7 @@
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:query-loop -->
</div>
<!-- /wp:query -->',
)
);
Expand All @@ -58,6 +62,7 @@
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true}} -->
<div class="wp-block-query">
<!-- wp:query-loop -->
<!-- wp:columns {"verticalAlignment":"center"} -->
<div class="wp-block-columns are-vertically-aligned-center"><!-- wp:column {"verticalAlignment":"center","width":"25%"} -->
Expand All @@ -68,6 +73,7 @@
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:query-loop -->
</div>
<!-- /wp:query -->',
)
);
Expand All @@ -79,13 +85,15 @@
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":6,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":true},"layout":{"type":"flex","columns":3}} -->
<div class="wp-block-query">
<!-- wp:query-loop -->
<!-- wp:group {"tagName":"main","style":{"spacing":{"padding":{"top":"30px","right":"30px","bottom":"30px","left":"30px"}}},"layout":{"inherit":false}} -->
<main class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt {"wordCount":20} /-->
<!-- wp:post-date /--></div>
<!-- /wp:group -->
<!-- /wp:query-loop -->
</div>
<!-- /wp:query -->',
)
);
Expand All @@ -98,7 +106,7 @@
'categories' => array( 'query' ),
'content' => '<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"100px","right":"100px","bottom":"100px","left":"100px"}},"color":{"text":"#ffffff","background":"#000000"}}} -->
<div class="wp-block-group alignfull has-text-color has-background" style="background-color:#000000;color:#ffffff;padding-top:100px;padding-right:100px;padding-bottom:100px;padding-left:100px"><!-- wp:query {"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true}} -->
<!-- wp:query-loop -->
<div class="wp-block-query"><!-- wp:query-loop -->
<!-- wp:separator {"customColor":"#ffffff","align":"wide","className":"is-style-wide"} -->
<hr class="wp-block-separator alignwide has-text-color has-background is-style-wide" style="background-color:#ffffff;color:#ffffff"/>
<!-- /wp:separator -->
Expand All @@ -112,7 +120,7 @@
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:80%"><!-- wp:post-title {"isLink":true,"style":{"typography":{"fontSize":"72px","lineHeight":"1.1"},"color":{"text":"#ffffff","link":"#ffffff"}}} /--></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:query-loop -->
<!-- /wp:query-loop --></div>
<!-- /wp:query --></div>
<!-- /wp:group -->',
)
Expand All @@ -128,26 +136,26 @@
<main class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"50%"} -->
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:query {"query":{"perPage":2,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"layout":{"type":"list"}} -->
<!-- wp:query-loop -->
<div class="wp-block-query"><!-- wp:query-loop -->
<!-- wp:post-featured-image /-->
<!-- wp:post-title /-->
<!-- wp:post-date /-->
<!-- wp:spacer {"height":200} -->
<div style="height:200px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- /wp:query-loop -->
<!-- /wp:query-loop --></div>
<!-- /wp:query --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"50%"} -->
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:query {"query":{"perPage":2,"pages":0,"offset":2,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"layout":{"type":"list"}} -->
<!-- wp:query-loop -->
<div class="wp-block-query"><!-- wp:query-loop -->
<!-- wp:spacer {"height":200} -->
<div style="height:200px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:post-featured-image /-->
<!-- wp:post-title /-->
<!-- wp:post-date /-->
<!-- /wp:query-loop -->
<!-- /wp:query-loop --></div>
<!-- /wp:query --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></main>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/query-pagination/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"category": "design",
"usesContext": [ "queryId", "query" ],
"supports": {
"align": true,
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
"reusable": false,
"html": false
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"layout": "layout"
},
"supports": {
"align": [ "wide", "full" ],
"html": false
},
"editorStyle": "wp-block-query-editor"
Expand Down
47 changes: 47 additions & 0 deletions packages/block-library/src/query/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';

const deprecated = [
// Version with NO wrapper `div` element.
{
attributes: {
queryId: {
type: 'number',
},
query: {
type: 'object',
default: {
perPage: null,
pages: 0,
offset: 0,
postType: 'post',
categoryIds: [],
tagIds: [],
order: 'desc',
orderBy: 'date',
author: '',
search: '',
exclude: [],
sticky: '',
inherit: true,
},
},
layout: {
type: 'object',
default: {
type: 'list',
},
},
},
supports: {
html: false,
},
save() {
return <InnerBlocks.Content />;
},
},
];

export default deprecated;
2 changes: 2 additions & 0 deletions packages/block-library/src/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import metadata from './block.json';
import edit from './edit';
import save from './save';
import variations from './variations';
import deprecated from './deprecated';

const { name } = metadata;
export { metadata, name };
Expand All @@ -22,4 +23,5 @@ export const settings = {
edit,
save,
variations,
deprecated,
};
8 changes: 6 additions & 2 deletions packages/block-library/src/query/save.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

export default function QuerySave() {
return <InnerBlocks.Content />;
return (
<div { ...useBlockProps.save() }>
<InnerBlocks.Content />
</div>
);
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/experimental-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const siteEditor = {
},

async getEditedPostContent() {
return await page.evaluate( async () => {
return page.evaluate( async () => {
const postId = window.wp.data
.select( 'core/edit-site' )
.getEditedPostId();
Expand Down
4 changes: 3 additions & 1 deletion packages/e2e-tests/fixtures/blocks/core__query.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<!-- wp:query /-->
<!-- wp:query -->
<div class="wp-block-query"></div>
<!-- /wp:query -->
2 changes: 1 addition & 1 deletion packages/e2e-tests/fixtures/blocks/core__query.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
}
},
"innerBlocks": [],
"originalContent": ""
"originalContent": "<div class=\"wp-block-query\"></div>"
}
]
6 changes: 4 additions & 2 deletions packages/e2e-tests/fixtures/blocks/core__query.parsed.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"blockName": "core/query",
"attrs": {},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
"innerHTML": "\n<div class=\"wp-block-query\"></div>\n",
"innerContent": [
"\n<div class=\"wp-block-query\"></div>\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<!-- wp:query /-->
<!-- wp:query -->
<div class="wp-block-query"></div>
<!-- /wp:query -->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:query /-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"clientId": "_clientId_0",
"name": "core/query",
"isValid": true,
"attributes": {
"query": {
"perPage": null,
"pages": 0,
"offset": 0,
"postType": "post",
"categoryIds": [],
"tagIds": [],
"order": "desc",
"orderBy": "date",
"author": "",
"search": "",
"exclude": [],
"sticky": "",
"inherit": true
},
"layout": {
"type": "list"
}
},
"innerBlocks": [],
"originalContent": ""
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"blockName": "core/query",
"attrs": {},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:query {"query":{"perPage":null,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"layout":{"type":"list"}} -->
Copy link
Member

Choose a reason for hiding this comment

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

As long as default value for attributes is used, it should look rather like:

<!-- wp:query -->
 <div class="wp-block-query"></div>
 <!-- /wp:query -->

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll investigate. I'm wondering if it has to do with these properties being objects that is not so common in core blocks. For example queryId is not here 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't be surprised. I think you know already my opinion about using complex key/value-based objects as attributes. I would avoid them in the first place, so if that creates an issue, we could use the opportunity that deprecation is inevitable to refactor that as well. Anyway, I hope that is something else and you don't have to end up with a nuclear option 🤣

Copy link
Contributor Author

@ntsekouras ntsekouras Apr 14, 2021

Choose a reason for hiding this comment

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

In some cases (Query being the main case that comes in my mind) it makes sense to use objects and we could always explore adding better support for them. Anyway..

How do you feel about this:494aa75

We could always use isEqual but felt like we could avoid the extra call for most cases that is not needed (not type object.

@youknowriad, @gziolo , @mcsf

<div class="wp-block-query"></div>
<!-- /wp:query -->