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