PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.2
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / blocks / text / index.js
generateblocks / src / blocks / text Last commit date
components 1 year ago block.json 1 year ago edit.js 1 year ago editor.scss 1 year ago index.js 1 year ago save.js 1 year ago transforms.js 1 year ago
index.js
62 lines
1 import { registerBlockType, registerBlockVariation } from '@wordpress/blocks';
2 import { __ } from '@wordpress/i18n';
3 import { Edit } from './edit';
4 import metadata from './block.json';
5 import { Save } from './save';
6 import { transforms } from './transforms';
7 import { getElementType } from '../element/utils/getElementType';
8 import { getIcon } from '@utils';
9
10 registerBlockType( metadata, {
11 edit: Edit,
12 save: Save,
13 icon: getIcon( 'text' ),
14 transforms,
15 __experimentalLabel: ( attrs, { context } ) => {
16 if ( 'list-view' === context ) {
17 if ( attrs?.metadata?.name ) {
18 return attrs.metadata.name;
19 }
20
21 const text = attrs.content?.text ?? attrs.content;
22
23 if ( text || attrs.iconOnly ) {
24 if ( attrs.iconOnly ) {
25 return __( 'Icon', 'generateblocks' );
26 }
27
28 return attrs.content;
29 }
30 }
31 },
32 } );
33
34 registerBlockVariation(
35 'generateblocks/text',
36 {
37 name: 'generateblocks/heading',
38 title: 'Headline',
39 description: __( 'A heading text element.', 'generateblocks' ),
40 icon: getIcon( 'headline' ),
41 attributes: {
42 tagName: 'h2',
43 },
44 isActive: ( blockAttributes ) => 'heading' === getElementType( blockAttributes.tagName ),
45 },
46 );
47
48 registerBlockVariation(
49 'generateblocks/text',
50 {
51 name: 'generateblocks/button',
52 title: 'Button',
53 description: __( 'An interactive button element.', 'generateblocks' ),
54 icon: getIcon( 'button' ),
55 attributes: {
56 tagName: 'a',
57 ...generateblocksBlockText.defaultButtonAttributes,
58 },
59 isActive: ( blockAttributes ) => 'button' === getElementType( blockAttributes.tagName ),
60 },
61 );
62