deprecated
2 months ago
block.json
23 hours ago
edit.js
2 months ago
heading-level-dropdown.js
2 months ago
heading-level-icon.js
2 months ago
icon.svg
2 months ago
index.js
2 months ago
index.php
2 months ago
save.js
2 months ago
style.scss
2 months ago
transforms.js
2 months ago
transforms.js
117 lines
| 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 |