Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 01124a6

Browse files
committed
move Block defs to block.json.
This also adds a bunch of layout controls to the top-level price block.
1 parent 53b3e48 commit 01124a6

File tree

4 files changed

+45
-53
lines changed

4 files changed

+45
-53
lines changed

assets/js/atomic/blocks/product-elements/price-v2/attributes.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"$schema": "http://schemas.wp.org/trunk/block.json",
3+
"apiVersion": 2,
4+
"name": "woocommerce/product-price-v2",
5+
"title": "Price",
6+
"keywords": "WooCommerce",
7+
"category": "woocommerce-product-elements",
8+
"textdomain": "woo-gutenberg-products-block",
9+
"description": "Display the price of a product, including any discounts.",
10+
"supports": {
11+
"__experimentalLayout": {
12+
"allowSwitching": false,
13+
"allowInheriting": false,
14+
"default": { "type": "flex" }
15+
},
16+
"html": false
17+
18+
},
19+
"usesContext": [ "queryId", "postId" ],
20+
"providesContext": {
21+
"woocommerce/isDescendentOfSingleProductTemplate":
22+
"isDescendentOfSingleProductTemplate",
23+
"woocommerce/isDescendentOfSingleProductBlock":
24+
"woocommerce/isDescendentOfSingleProductBlock"
25+
},
26+
"attributes": {
27+
"isDescendentOfSingleProductTemplate": {
28+
"type": "boolean",
29+
"default": false
30+
},
31+
"isDescendentOfSingleProductBlock": {
32+
"type": "boolean",
33+
"default": false
34+
},
35+
"productId": {
36+
"type": "number",
37+
"default": 0
38+
}
39+
}
40+
}
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
/**
22
* External dependencies
33
*/
4-
import { __ } from '@wordpress/i18n';
54
import { currencyDollar, Icon } from '@wordpress/icons';
65

7-
export const BLOCK_TITLE: string = __(
8-
'Price',
9-
'woo-gutenberg-products-block'
10-
);
116
export const BLOCK_ICON: JSX.Element = (
127
<Icon
138
icon={ currencyDollar }
149
className="wc-block-editor-components-block-icon"
1510
/>
1611
);
17-
export const BLOCK_DESCRIPTION: string = __(
18-
'Display the price of a product, including any discounts.',
19-
'woo-gutenberg-products-block'
20-
);

assets/js/atomic/blocks/product-elements/price-v2/index.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,18 @@ import { registerBlockType } from '@wordpress/blocks';
66
/**
77
* Internal dependencies
88
*/
9-
import sharedConfig from '../shared/config';
109
import edit from './edit';
1110
import save from './save';
12-
import attributes from './attributes';
1311
import { supports } from './supports';
14-
import {
15-
BLOCK_TITLE as title,
16-
BLOCK_ICON as icon,
17-
BLOCK_DESCRIPTION as description,
18-
} from './constants';
19-
20-
const { ancestor, ...configuration } = sharedConfig;
12+
import metadata from './block.json';
13+
import { BLOCK_ICON as icon } from './constants';
2114

2215
const blockConfig = {
23-
...configuration,
24-
apiVersion: 2,
25-
title,
26-
description,
27-
usesContext: [ 'postId', 'queryId' ],
28-
providesContext: {
29-
'woocommerce/isDescendentOfSingleProductTemplate':
30-
'isDescendentOfSingleProductTemplate',
31-
'woocommerce/isDescendentOfSingleProductBlock':
32-
'isDescendentOfSingleProductBlock',
33-
},
16+
...metadata,
3417
icon: { src: icon },
35-
attributes,
36-
supports,
18+
supports: { ...supports, ...metadata.supports },
3719
edit,
3820
save,
3921
};
4022

41-
registerBlockType( 'woocommerce/product-price-v2', blockConfig );
23+
registerBlockType( metadata.name, blockConfig );

0 commit comments

Comments
 (0)