Skip to content

Commit

Permalink
Add wrapper in Query block
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Apr 16, 2021
1 parent 5a06916 commit 2fbd5d9
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 8 deletions.
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,
"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>
);
}
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>"
}
]
10 changes: 7 additions & 3 deletions packages/e2e-tests/fixtures/blocks/core__query.parsed.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
"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"
]
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n",
"innerContent": [ "\n" ]
"innerContent": [
"\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 /-->
29 changes: 29 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__query__deprecated-1.json
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,18 @@
[
{
"blockName": "core/query",
"attrs": {},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n",
"innerContent": [
"\n"
]
}
]
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"}} -->
<div class="wp-block-query"></div>
<!-- /wp:query -->

0 comments on commit 2fbd5d9

Please sign in to comment.