css
5 years ago
attributes.js
5 years ago
block.js
5 years ago
deprecated.js
5 years ago
edit.js
5 years ago
editor.scss
5 years ago
element-icons.js
5 years ago
markformat.js
5 years ago
save.js
5 years ago
transforms.js
5 years ago
deprecated.js
168 lines
| 1 | import blockAttributes from './attributes'; |
| 2 | import classnames from 'classnames'; |
| 3 | import sanitizeSVG from '../../utils/sanitize-svg'; |
| 4 | |
| 5 | import { |
| 6 | RichText, |
| 7 | } from '@wordpress/block-editor'; |
| 8 | |
| 9 | import { |
| 10 | applyFilters, |
| 11 | } from '@wordpress/hooks'; |
| 12 | |
| 13 | const deprecated = [ |
| 14 | // v2 - remove wrapper. |
| 15 | { |
| 16 | attributes: { |
| 17 | ...blockAttributes, |
| 18 | content: { |
| 19 | type: 'array', |
| 20 | source: 'children', |
| 21 | selector: 'p,h1,h2,h3,h4,h5,h6', |
| 22 | }, |
| 23 | }, |
| 24 | supports: { |
| 25 | anchor: false, |
| 26 | className: false, |
| 27 | customClassName: false, |
| 28 | }, |
| 29 | migrate( attributes ) { |
| 30 | const oldClasses = attributes.cssClasses ? attributes.cssClasses : attributes.className; |
| 31 | const oldAnchor = attributes.elementId ? attributes.elementId : attributes.anchor; |
| 32 | let currentElement = ( attributes.element ? attributes.element : generateBlocksDefaults.headline.element ); |
| 33 | |
| 34 | if ( attributes.icon && attributes.removeText && 'div' !== currentElement ) { |
| 35 | currentElement = 'div'; |
| 36 | } |
| 37 | |
| 38 | return { |
| 39 | ...attributes, |
| 40 | className: oldClasses, |
| 41 | anchor: oldAnchor, |
| 42 | cssClasses: '', |
| 43 | elementId: '', |
| 44 | element: currentElement, |
| 45 | }; |
| 46 | }, |
| 47 | save( { attributes } ) { |
| 48 | const { |
| 49 | uniqueId, |
| 50 | elementId, |
| 51 | cssClasses, |
| 52 | element, |
| 53 | content, |
| 54 | icon, |
| 55 | removeText, |
| 56 | ariaLabel, |
| 57 | } = attributes; |
| 58 | |
| 59 | const ConditionalWrap = ( { condition, wrap, children } ) => condition ? wrap( children ) : children; |
| 60 | |
| 61 | let htmlAttributes = { |
| 62 | id: !! elementId ? elementId : undefined, |
| 63 | className: classnames( { |
| 64 | 'gb-headline': true, |
| 65 | [ `gb-headline-${ uniqueId }` ]: true, |
| 66 | [ `${ cssClasses }` ]: '' !== cssClasses, |
| 67 | } ), |
| 68 | }; |
| 69 | |
| 70 | htmlAttributes = applyFilters( 'generateblocks.frontend.htmlAttributes', htmlAttributes, 'generateblocks/headline', attributes ); |
| 71 | |
| 72 | return ( |
| 73 | <ConditionalWrap |
| 74 | condition={ icon } |
| 75 | wrap={ ( children ) => <div className={ classnames( { |
| 76 | 'gb-headline-wrapper': true, |
| 77 | [ `gb-headline-wrapper-${ uniqueId }` ]: true, |
| 78 | } ) }>{ children }</div> } |
| 79 | > |
| 80 | { icon && |
| 81 | <span |
| 82 | className="gb-icon" |
| 83 | aria-label={ !! removeText && !! ariaLabel ? ariaLabel : undefined } |
| 84 | dangerouslySetInnerHTML={ { __html: sanitizeSVG( icon ) } } |
| 85 | /> |
| 86 | } |
| 87 | |
| 88 | { ! removeText && |
| 89 | <RichText.Content |
| 90 | tagName={ element } |
| 91 | value={ content } |
| 92 | { ...htmlAttributes } |
| 93 | /> |
| 94 | } |
| 95 | </ConditionalWrap> |
| 96 | ); |
| 97 | }, |
| 98 | }, |
| 99 | // v1 - change default h2 to p. |
| 100 | { |
| 101 | attributes: { |
| 102 | ...blockAttributes, |
| 103 | element: { |
| 104 | type: 'string', |
| 105 | default: 'p', |
| 106 | }, |
| 107 | content: { |
| 108 | type: 'array', |
| 109 | source: 'children', |
| 110 | selector: 'p,h1,h2,h3,h4,h5,h6', |
| 111 | }, |
| 112 | }, |
| 113 | save( { attributes } ) { |
| 114 | const { |
| 115 | uniqueId, |
| 116 | elementId, |
| 117 | cssClasses, |
| 118 | element, |
| 119 | content, |
| 120 | icon, |
| 121 | removeText, |
| 122 | ariaLabel, |
| 123 | } = attributes; |
| 124 | |
| 125 | const ConditionalWrap = ( { condition, wrap, children } ) => condition ? wrap( children ) : children; |
| 126 | |
| 127 | let htmlAttributes = { |
| 128 | id: !! elementId ? elementId : undefined, |
| 129 | className: classnames( { |
| 130 | 'gb-headline': true, |
| 131 | [ `gb-headline-${ uniqueId }` ]: true, |
| 132 | [ `${ cssClasses }` ]: '' !== cssClasses, |
| 133 | } ), |
| 134 | }; |
| 135 | |
| 136 | htmlAttributes = applyFilters( 'generateblocks.frontend.htmlAttributes', htmlAttributes, 'generateblocks/headline', attributes ); |
| 137 | |
| 138 | return ( |
| 139 | <ConditionalWrap |
| 140 | condition={ icon } |
| 141 | wrap={ ( children ) => <div className={ classnames( { |
| 142 | 'gb-headline-wrapper': true, |
| 143 | [ `gb-headline-wrapper-${ uniqueId }` ]: true, |
| 144 | } ) }>{ children }</div> } |
| 145 | > |
| 146 | { icon && |
| 147 | <span |
| 148 | className="gb-icon" |
| 149 | aria-label={ !! removeText && !! ariaLabel ? ariaLabel : undefined } |
| 150 | dangerouslySetInnerHTML={ { __html: sanitizeSVG( icon ) } } |
| 151 | /> |
| 152 | } |
| 153 | |
| 154 | { ! removeText && |
| 155 | <RichText.Content |
| 156 | tagName={ element } |
| 157 | value={ content } |
| 158 | { ...htmlAttributes } |
| 159 | /> |
| 160 | } |
| 161 | </ConditionalWrap> |
| 162 | ); |
| 163 | }, |
| 164 | }, |
| 165 | ]; |
| 166 | |
| 167 | export default deprecated; |
| 168 |