PluginProbe
VK Blocks / 1.122.0
VK Blocks v1.122.0
1.126.4 1.126.3 1.126.1 1.126.2 1.126.0 1.125.0 1.124.0 1.123.0 1.122.0 1.121.0 1.120.0 1.119.2 1.119.1 1.119.0 1.118.7 1.82.0.0 1.82.0.1 1.83.0.0 1.83.0.1 1.84.0.0 1.84.0.1 1.85.0.2 1.85.0.3 1.85.1.0 1.85.1.1 All 287 releases
vk-blocks / src / blocks / heading / transforms.js
transforms.js
117 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { createBlock } from '@wordpress/blocks';
2
3 const transforms = {
4 from: [
5 {
6 type: 'block',
7 blocks: ['core/heading'],
8 transform: (attributes) => {
9 const { content } = attributes;
10
11 const transformAttributes = {
12 title: content,
13 };
14
15 return createBlock('vk-blocks/heading', transformAttributes);
16 },
17 },
18 ],
19 to: [
20 {
21 type: 'block',
22 blocks: ['core/heading'],
23 transform: (attributes) => {
24 const {
25 title,
26 level,
27 anchor,
28 align,
29 outerMarginBottom,
30 titleMarginBottom,
31 titleColor,
32 titleSize,
33 subTextFlag,
34 subText,
35 subTextColor,
36 subTextSize,
37 } = attributes;
38
39 let headingMarginBottom;
40 if (subTextFlag === 'on' && !!titleMarginBottom) {
41 headingMarginBottom = titleMarginBottom + 'rem';
42 } else if (subTextFlag === 'off' && !!outerMarginBottom) {
43 headingMarginBottom = outerMarginBottom + 'rem';
44 }
45
46 let headingFontSize;
47 if (!!titleSize) {
48 headingFontSize = titleSize + 'rem';
49 }
50
51 let paragraphMarginBottom;
52 if (subTextFlag === 'on' && !!outerMarginBottom) {
53 paragraphMarginBottom = outerMarginBottom + 'rem';
54 }
55
56 let paragraphFontSize;
57 if (!!subTextSize) {
58 paragraphFontSize = subTextSize + 'rem';
59 }
60
61 const transformHeadingAttributes = {
62 ...attributes,
63 content: title,
64 level,
65 anchor,
66 textAlign: align,
67 textColor: titleColor,
68 style: {
69 spacing: {
70 margin: {
71 bottom: headingMarginBottom,
72 },
73 },
74 typography: {
75 fontSize: headingFontSize,
76 },
77 },
78 };
79
80 const transformParagraphAttributes = {
81 ...attributes,
82 content: subText,
83 align,
84 textColor: subTextColor,
85 style: {
86 spacing: {
87 margin: {
88 bottom: paragraphMarginBottom,
89 },
90 },
91 typography: {
92 fontSize: paragraphFontSize,
93 },
94 },
95 };
96
97 const blockContent = [];
98
99 blockContent.push(
100 createBlock('core/heading', transformHeadingAttributes)
101 );
102 if (subTextFlag === 'on') {
103 blockContent.push(
104 createBlock(
105 'core/paragraph',
106 transformParagraphAttributes
107 )
108 );
109 }
110 return blockContent;
111 },
112 },
113 ],
114 };
115
116 export default transforms;
117