PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.0
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 / container / transforms.js
generateblocks / src / blocks / container Last commit date
components 1 year ago css 2 years ago attributes.js 2 years ago block-controls.js 2 years ago block.js 1 year ago deprecated.js 3 years ago edit.js 2 years ago editor.scss 1 year ago transforms.js 1 year ago
transforms.js
94 lines
1 import { convertLegacyHtmlAttributes } from '@utils/convertLegacyHtmlAttributes';
2 import { convertLocalToStyles } from '@utils/legacyStyleUtils';
3 import { createBlock, getBlockType } from '@wordpress/blocks';
4
5 export const transforms = {
6 to: [
7 {
8 type: 'block',
9 blocks: [ 'generateblocks/element' ],
10 isMatch: ( {
11 useInnerContainer,
12 variantRole,
13 shapeDividers,
14 googleFont,
15 isGrid,
16 isQueryLoopItem,
17 useGlobalStyle = false,
18 isGlobalStyle = false,
19 } ) => {
20 if (
21 useInnerContainer ||
22 variantRole ||
23 shapeDividers.length > 0 ||
24 googleFont ||
25 isGrid ||
26 isQueryLoopItem ||
27 useGlobalStyle ||
28 isGlobalStyle
29 ) {
30 return false;
31 }
32
33 return true;
34 },
35 transform: ( attributes, blocks ) => {
36 const {
37 tagName,
38 htmlAttributes,
39 blockLabel,
40 globalClasses,
41 anchor,
42 className,
43 url,
44 } = attributes;
45 const attributeData = getBlockType( 'generateblocks/container' )?.attributes;
46 const styles = convertLocalToStyles( attributeData, attributes, '&:is(:hover, :focus)' );
47 const newHtmlAttributes = convertLegacyHtmlAttributes( htmlAttributes );
48
49 if ( anchor ) {
50 newHtmlAttributes.id = anchor;
51 }
52
53 if ( url ) {
54 newHtmlAttributes.href = url;
55 }
56
57 const metaData = {};
58
59 if ( blockLabel ) {
60 metaData.name = blockLabel;
61 }
62
63 // Clone the Blocks to be Grouped
64 // Failing to create new block references causes the original blocks
65 // to be replaced in the switchToBlockType call thereby meaning they
66 // are removed both from their original location and within the
67 // new group block.
68 const groupInnerBlocks = blocks.map( ( block ) => {
69 return createBlock(
70 block.name,
71 block.attributes,
72 block.innerBlocks
73 );
74 } );
75
76 const newTagName = url ? 'a' : tagName;
77
78 return createBlock(
79 'generateblocks/element',
80 {
81 tagName: newTagName,
82 styles,
83 htmlAttributes: newHtmlAttributes,
84 metadata: metaData,
85 globalClasses,
86 className,
87 },
88 groupInnerBlocks
89 );
90 },
91 },
92 ],
93 };
94