2019-01-10 18:16:37 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-02-26 05:31:25 +00:00
|
|
|
import { createBlock, registerBlockType } from '@wordpress/blocks';
|
2019-01-10 18:16:37 +00:00
|
|
|
import Gridicon from 'gridicons';
|
2019-05-28 12:06:12 +00:00
|
|
|
import { without } from 'lodash';
|
2019-01-10 18:16:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Block from './block';
|
2019-05-28 12:06:12 +00:00
|
|
|
import { deprecatedConvertToShortcode } from '../../utils/deprecations';
|
2019-09-05 15:09:31 +00:00
|
|
|
import sharedAttributes, {
|
|
|
|
sharedAttributeBlockTypes,
|
|
|
|
} from '../../utils/shared-attributes';
|
2019-01-10 18:16:37 +00:00
|
|
|
|
2019-05-28 12:06:12 +00:00
|
|
|
const blockTypeName = 'woocommerce/product-top-rated';
|
|
|
|
|
|
|
|
registerBlockType( blockTypeName, {
|
2019-01-10 18:16:37 +00:00
|
|
|
title: __( 'Top Rated Products', 'woo-gutenberg-products-block' ),
|
2019-05-28 10:18:07 +00:00
|
|
|
icon: {
|
|
|
|
src: <Gridicon icon="trophy" />,
|
|
|
|
foreground: '#96588a',
|
|
|
|
},
|
2019-01-10 18:16:37 +00:00
|
|
|
category: 'woocommerce',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __(
|
|
|
|
'Display a grid of your top rated products.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
supports: {
|
|
|
|
align: [ 'wide', 'full' ],
|
2019-08-06 14:10:01 +00:00
|
|
|
html: false,
|
2019-01-10 18:16:37 +00:00
|
|
|
},
|
2019-11-15 15:16:18 +00:00
|
|
|
example: {
|
|
|
|
attributes: {
|
|
|
|
isPreview: true,
|
|
|
|
},
|
|
|
|
},
|
2019-01-10 18:16:37 +00:00
|
|
|
attributes: {
|
|
|
|
...sharedAttributes,
|
|
|
|
},
|
2019-05-28 12:06:12 +00:00
|
|
|
|
2019-02-26 05:31:25 +00:00
|
|
|
transforms: {
|
|
|
|
from: [
|
|
|
|
{
|
|
|
|
type: 'block',
|
2019-05-28 12:06:12 +00:00
|
|
|
blocks: without( sharedAttributeBlockTypes, blockTypeName ),
|
2019-09-05 15:09:31 +00:00
|
|
|
transform: ( attributes ) =>
|
|
|
|
createBlock( 'woocommerce/product-top-rated', attributes ),
|
2019-02-26 05:31:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-01-10 18:16:37 +00:00
|
|
|
|
2019-05-28 12:06:12 +00:00
|
|
|
deprecated: [
|
|
|
|
{
|
|
|
|
// Deprecate shortcode save method in favor of dynamic rendering.
|
|
|
|
attributes: sharedAttributes,
|
|
|
|
save: deprecatedConvertToShortcode( blockTypeName ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2019-01-10 18:16:37 +00:00
|
|
|
/**
|
|
|
|
* Renders and manages the block.
|
2019-12-10 17:17:46 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Props to pass to block.
|
2019-01-10 18:16:37 +00:00
|
|
|
*/
|
|
|
|
edit( props ) {
|
|
|
|
return <Block { ...props } />;
|
|
|
|
},
|
|
|
|
|
2019-05-28 12:06:12 +00:00
|
|
|
save() {
|
|
|
|
return null;
|
2019-01-10 18:16:37 +00:00
|
|
|
},
|
|
|
|
} );
|