css
4 years ago
attributes.js
4 years ago
block-controls.js
4 years ago
block.js
4 years ago
deprecated.js
5 years ago
edit.js
4 years ago
editor.scss
4 years ago
deprecated.js
88 lines
| 1 | /** |
| 2 | * External dependencies |
| 3 | */ |
| 4 | import classnames from 'classnames'; |
| 5 | import Element from '../../components/element'; |
| 6 | import blockAttributes from './attributes'; |
| 7 | |
| 8 | import { |
| 9 | applyFilters, |
| 10 | } from '@wordpress/hooks'; |
| 11 | |
| 12 | import { |
| 13 | InnerBlocks, |
| 14 | } from '@wordpress/block-editor'; |
| 15 | |
| 16 | const deprecated = [ |
| 17 | // v1 of container block. Deprecated the gb-grid-column wrapper in save component. |
| 18 | { |
| 19 | attributes: blockAttributes, |
| 20 | supports: { |
| 21 | align: false, |
| 22 | anchor: false, |
| 23 | className: false, |
| 24 | customClassName: false, |
| 25 | }, |
| 26 | migrate( attributes ) { |
| 27 | const oldClasses = attributes.cssClasses ? attributes.cssClasses : attributes.className; |
| 28 | const oldAnchor = attributes.elementId ? attributes.elementId : attributes.anchor; |
| 29 | |
| 30 | return { |
| 31 | ...attributes, |
| 32 | className: oldClasses, |
| 33 | anchor: oldAnchor, |
| 34 | cssClasses: '', |
| 35 | elementId: '', |
| 36 | }; |
| 37 | }, |
| 38 | save( { attributes } ) { |
| 39 | const { |
| 40 | uniqueId, |
| 41 | tagName, |
| 42 | elementId, |
| 43 | cssClasses, |
| 44 | isGrid, |
| 45 | align, |
| 46 | } = attributes; |
| 47 | |
| 48 | const ConditionalWrap = ( { condition, wrap, children } ) => condition ? wrap( children ) : children; |
| 49 | |
| 50 | let htmlAttributes = { |
| 51 | className: classnames( { |
| 52 | 'gb-container': true, |
| 53 | [ `gb-container-${ uniqueId }` ]: true, |
| 54 | [ `${ cssClasses }` ]: '' !== cssClasses, |
| 55 | [ `align${ align }` ]: !! align && ! isGrid, |
| 56 | } ), |
| 57 | id: elementId ? elementId : null, |
| 58 | }; |
| 59 | |
| 60 | htmlAttributes = applyFilters( 'generateblocks.frontend.htmlAttributes', htmlAttributes, 'generateblocks/container', attributes ); |
| 61 | |
| 62 | return ( |
| 63 | <ConditionalWrap |
| 64 | condition={ isGrid } |
| 65 | wrap={ ( children ) => <div className={ classnames( { |
| 66 | 'gb-grid-column': true, |
| 67 | [ `gb-grid-column-${ uniqueId }` ]: true, |
| 68 | } ) }>{ children }</div> } |
| 69 | > |
| 70 | <Element |
| 71 | tagName={ tagName } |
| 72 | htmlAttrs={ htmlAttributes } |
| 73 | > |
| 74 | { applyFilters( 'generateblocks.frontend.insideContainer', '', attributes ) } |
| 75 | <div className={ classnames( { |
| 76 | 'gb-inside-container': true, |
| 77 | } ) }> |
| 78 | <InnerBlocks.Content /> |
| 79 | </div> |
| 80 | </Element> |
| 81 | </ConditionalWrap> |
| 82 | ); |
| 83 | }, |
| 84 | }, |
| 85 | ]; |
| 86 | |
| 87 | export default deprecated; |
| 88 |