@wordpress/block-library
Version:
Block library for the WordPress editor.
152 lines (140 loc) • 3.24 kB
JavaScript
import { createElement } from "@wordpress/element";
/**
* WordPress dependencies
*/
import { InnerBlocks, useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';
const migrateToTaxQuery = attributes => {
var _query$categoryIds, _query$tagIds;
const {
query
} = attributes;
const {
categoryIds,
tagIds,
...newQuery
} = query;
if ((_query$categoryIds = query.categoryIds) !== null && _query$categoryIds !== void 0 && _query$categoryIds.length || (_query$tagIds = query.tagIds) !== null && _query$tagIds !== void 0 && _query$tagIds.length) {
var _query$categoryIds2, _query$tagIds2;
newQuery.taxQuery = {
category: !!((_query$categoryIds2 = query.categoryIds) !== null && _query$categoryIds2 !== void 0 && _query$categoryIds2.length) ? query.categoryIds : undefined,
post_tag: !!((_query$tagIds2 = query.tagIds) !== null && _query$tagIds2 !== void 0 && _query$tagIds2.length) ? query.tagIds : undefined
};
}
return { ...attributes,
query: newQuery
};
};
const deprecated = [// Version with `categoryIds and tagIds`.
{
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
}
},
tagName: {
type: 'string',
default: 'div'
},
displayLayout: {
type: 'object',
default: {
type: 'list'
}
}
},
supports: {
align: ['wide', 'full'],
html: false,
color: {
gradients: true,
link: true
},
__experimentalLayout: true
},
isEligible: _ref => {
let {
query: {
categoryIds,
tagIds
} = {}
} = _ref;
return categoryIds || tagIds;
},
migrate: migrateToTaxQuery,
save(_ref2) {
let {
attributes: {
tagName: Tag = 'div'
}
} = _ref2;
const blockProps = useBlockProps.save();
const innerBlocksProps = useInnerBlocksProps.save(blockProps);
return createElement(Tag, innerBlocksProps);
}
}, // 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
},
migrate(attributes) {
const withTaxQuery = migrateToTaxQuery(attributes);
const {
layout,
...restWithTaxQuery
} = withTaxQuery;
return { ...restWithTaxQuery,
displayLayout: withTaxQuery.layout
};
},
save() {
return createElement(InnerBlocks.Content, null);
}
}];
export default deprecated;
//# sourceMappingURL=deprecated.js.map