| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 7 |
var MediaUploadCheck = wp.blockEditor.MediaUploadCheck; |
| 8 |
var RichText = wp.blockEditor.RichText; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 11 |
var SelectControl = wp.components.SelectControl; |
| 12 |
var ToggleControl = wp.components.ToggleControl; |
| 13 |
var RangeControl = wp.components.RangeControl; |
| 14 |
var Button = wp.components.Button; |
| 15 |
|
| 16 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 17 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 18 |
|
| 19 |
var QUOTE_MARKS = { |
| 20 |
curved: '\u201C\u201D', |
| 21 |
straight: '"\u0022"', |
| 22 |
double: '\u00AB\u00BB', |
| 23 |
none: '' |
| 24 |
}; |
| 25 |
|
| 26 |
var v1Attributes = { |
| 27 |
quoteText: { type: 'string', default: 'Design is not just what it looks like and feels like. Design is how it works.' }, |
| 28 |
authorName: { type: 'string', default: 'Steve Jobs' }, |
| 29 |
authorRole: { type: 'string', default: 'Co-founder, Apple' }, |
| 30 |
showAvatar: { type: 'boolean', default: false }, |
| 31 |
avatarUrl: { type: 'string', default: '' }, |
| 32 |
avatarId: { type: 'number', default: 0 }, |
| 33 |
avatarSize: { type: 'number', default: 56 }, |
| 34 |
quoteMarkStyle: { type: 'string', default: 'curved' }, |
| 35 |
layout: { type: 'string', default: 'center' }, |
| 36 |
showAccent: { type: 'boolean', default: true }, |
| 37 |
accentPosition: { type: 'string', default: 'left' }, |
| 38 |
accentColor: { type: 'string', default: '#6c3fb5' }, |
| 39 |
accentWidth: { type: 'number', default: 4 }, |
| 40 |
bgColor: { type: 'string', default: '' }, |
| 41 |
textColor: { type: 'string', default: '#222222' }, |
| 42 |
markColor: { type: 'string', default: '#d1c4e9' }, |
| 43 |
quoteSz: { type: 'number', default: 22 }, |
| 44 |
authorSz: { type: 'number', default: 14 }, |
| 45 |
preset: { type: 'string', default: 'editorial' }, |
| 46 |
borderRadius: { type: 'number', default: 8 }, |
| 47 |
paddingV: { type: 'number', default: 40 }, |
| 48 |
paddingH: { type: 'number', default: 40 }, |
| 49 |
shadow: { type: 'boolean', default: false }, |
| 50 |
quoteFontWeight: { type: 'number', default: 400 }, |
| 51 |
quoteLineHeight: { type: 'number', default: 1.7 }, |
| 52 |
authorFontWeight: { type: 'number', default: 600 }, |
| 53 |
authorLineHeight: { type: 'number', default: 1.4 } |
| 54 |
}; |
| 55 |
|
| 56 |
registerBlockType( 'blockenberg/pullquote-pro', { |
| 57 |
deprecated: [{ |
| 58 |
attributes: v1Attributes, |
| 59 |
save: function (props) { |
| 60 |
var attrs = props.attributes; |
| 61 |
var RichText = wp.blockEditor.RichText; |
| 62 |
var mark = QUOTE_MARKS[attrs.quoteMarkStyle] || QUOTE_MARKS.curved; |
| 63 |
var openMark = mark ? mark[0] : ''; |
| 64 |
return el('blockquote', { |
| 65 |
className: [ |
| 66 |
'bkqp-wrap', |
| 67 |
'bkqp-layout-' + attrs.layout, |
| 68 |
'bkqp-preset-' + attrs.preset, |
| 69 |
attrs.showAccent ? 'bkqp-accent-' + attrs.accentPosition : '', |
| 70 |
attrs.shadow ? 'bkqp-shadow' : '' |
| 71 |
].filter(Boolean).join(' '), |
| 72 |
style: { |
| 73 |
'--bkqp-bg': attrs.bgColor || 'transparent', |
| 74 |
'--bkqp-text': attrs.textColor, |
| 75 |
'--bkqp-mark': attrs.markColor, |
| 76 |
'--bkqp-accent': attrs.accentColor, |
| 77 |
'--bkqp-accentW': attrs.accentWidth + 'px', |
| 78 |
'--bkqp-qSz': attrs.quoteSz + 'px', |
| 79 |
'--bkqp-qFw': attrs.quoteFontWeight, |
| 80 |
'--bkqp-qLh': attrs.quoteLineHeight, |
| 81 |
'--bkqp-aSz': attrs.authorSz + 'px', |
| 82 |
'--bkqp-aFw': attrs.authorFontWeight, |
| 83 |
'--bkqp-aLh': attrs.authorLineHeight, |
| 84 |
'--bkqp-pv': attrs.paddingV + 'px', |
| 85 |
'--bkqp-ph': attrs.paddingH + 'px', |
| 86 |
'--bkqp-radius': attrs.borderRadius + 'px', |
| 87 |
'--bkqp-avatarSz': attrs.avatarSize + 'px' |
| 88 |
} |
| 89 |
}, |
| 90 |
attrs.quoteMarkStyle !== 'none' && el('span', { className: 'bkqp-mark', 'aria-hidden': 'true' }, openMark), |
| 91 |
el(RichText.Content, { tagName: 'p', className: 'bkqp-text', value: attrs.quoteText }), |
| 92 |
el('footer', { className: 'bkqp-footer' }, |
| 93 |
attrs.showAvatar && attrs.avatarUrl && el('img', { |
| 94 |
className: 'bkqp-avatar', |
| 95 |
src: attrs.avatarUrl, |
| 96 |
alt: attrs.authorName, |
| 97 |
loading: 'lazy' |
| 98 |
}), |
| 99 |
el('div', { className: 'bkqp-cite' }, |
| 100 |
el(RichText.Content, { tagName: 'cite', className: 'bkqp-author', value: attrs.authorName }), |
| 101 |
el(RichText.Content, { tagName: 'small', className: 'bkqp-role', value: attrs.authorRole }) |
| 102 |
) |
| 103 |
) |
| 104 |
); |
| 105 |
} |
| 106 |
}], |
| 107 |
edit: function ( props ) { |
| 108 |
var attrs = props.attributes; |
| 109 |
var setAttr = props.setAttributes; |
| 110 |
var mark = QUOTE_MARKS[ attrs.quoteMarkStyle ] || QUOTE_MARKS.curved; |
| 111 |
var openMark = mark ? mark[0] : ''; |
| 112 |
|
| 113 |
var TC = getTypoControl(); |
| 114 |
var wrapStyle = (function () { |
| 115 |
var _tv = getTypoCssVars(); |
| 116 |
var s = { |
| 117 |
'--bkqp-bg': attrs.bgColor || 'transparent', |
| 118 |
'--bkqp-text': attrs.textColor, |
| 119 |
'--bkqp-mark': attrs.markColor, |
| 120 |
'--bkqp-accent': attrs.accentColor, |
| 121 |
'--bkqp-accentW': attrs.accentWidth + 'px', |
| 122 |
'--bkqp-pv': attrs.paddingV + 'px', |
| 123 |
'--bkqp-ph': attrs.paddingH + 'px', |
| 124 |
'--bkqp-radius': attrs.borderRadius + 'px', |
| 125 |
'--bkqp-avatarSz': attrs.avatarSize + 'px' |
| 126 |
}; |
| 127 |
if (_tv) { |
| 128 |
Object.assign(s, _tv(attrs.quoteTypo || {}, '--bkqp-qt-')); |
| 129 |
Object.assign(s, _tv(attrs.authorTypo || {}, '--bkqp-au-')); |
| 130 |
} |
| 131 |
return s; |
| 132 |
})(); |
| 133 |
|
| 134 |
return el( 'div', null, |
| 135 |
el( InspectorControls, null, |
| 136 |
el( PanelBody, { title: __( 'Quote Style', 'blockenberg' ), initialOpen: true }, |
| 137 |
el( SelectControl, { |
| 138 |
label: __( 'Quote Mark Style', 'blockenberg' ), |
| 139 |
value: attrs.quoteMarkStyle, |
| 140 |
options: [ |
| 141 |
{ label: 'Curved (" ")', value: 'curved' }, |
| 142 |
{ label: 'Straight (" ")', value: 'straight' }, |
| 143 |
{ label: 'Guillemets (« »)', value: 'double' }, |
| 144 |
{ label: 'None', value: 'none' } |
| 145 |
], |
| 146 |
onChange: function (v) { setAttr({ quoteMarkStyle: v }); } |
| 147 |
} ), |
| 148 |
el( SelectControl, { |
| 149 |
label: __( 'Layout / Alignment', 'blockenberg' ), |
| 150 |
value: attrs.layout, |
| 151 |
options: [ |
| 152 |
{ label: 'Center', value: 'center' }, |
| 153 |
{ label: 'Left', value: 'left' }, |
| 154 |
{ label: 'Right', value: 'right' }, |
| 155 |
{ label: 'Float Left', value: 'float-left' } |
| 156 |
], |
| 157 |
onChange: function (v) { setAttr({ layout: v }); } |
| 158 |
} ), |
| 159 |
el( SelectControl, { |
| 160 |
label: __( 'Typography Preset', 'blockenberg' ), |
| 161 |
value: attrs.preset, |
| 162 |
options: [ |
| 163 |
{ label: 'Editorial', value: 'editorial' }, |
| 164 |
{ label: 'Elegant', value: 'elegant' }, |
| 165 |
{ label: 'Loud', value: 'loud' } |
| 166 |
], |
| 167 |
onChange: function (v) { setAttr({ preset: v }); } |
| 168 |
} ), |
| 169 |
el( ToggleControl, { |
| 170 |
label: __( 'Show Accent Line', 'blockenberg' ), |
| 171 |
checked: attrs.showAccent, |
| 172 |
onChange: function (v) { setAttr({ showAccent: v }); }, |
| 173 |
__nextHasNoMarginBottom: true |
| 174 |
} ), |
| 175 |
attrs.showAccent && el( SelectControl, { |
| 176 |
label: __( 'Accent Position', 'blockenberg' ), |
| 177 |
value: attrs.accentPosition, |
| 178 |
options: [ |
| 179 |
{ label: 'Left', value: 'left' }, |
| 180 |
{ label: 'Top', value: 'top' }, |
| 181 |
{ label: 'Bottom', value: 'bottom' } |
| 182 |
], |
| 183 |
onChange: function (v) { setAttr({ accentPosition: v }); } |
| 184 |
} ), |
| 185 |
attrs.showAccent && el( RangeControl, { |
| 186 |
label: __( 'Accent Width (px)', 'blockenberg' ), |
| 187 |
value: attrs.accentWidth, min: 2, max: 12, |
| 188 |
onChange: function (v) { setAttr({ accentWidth: v }); } |
| 189 |
} ), |
| 190 |
el( RangeControl, { |
| 191 |
label: __( 'Vertical Padding (px)', 'blockenberg' ), |
| 192 |
value: attrs.paddingV, min: 16, max: 80, |
| 193 |
onChange: function (v) { setAttr({ paddingV: v }); } |
| 194 |
} ), |
| 195 |
el( RangeControl, { |
| 196 |
label: __( 'Horizontal Padding (px)', 'blockenberg' ), |
| 197 |
value: attrs.paddingH, min: 16, max: 80, |
| 198 |
onChange: function (v) { setAttr({ paddingH: v }); } |
| 199 |
} ), |
| 200 |
el( RangeControl, { |
| 201 |
label: __( 'Border Radius (px)', 'blockenberg' ), |
| 202 |
value: attrs.borderRadius, min: 0, max: 24, |
| 203 |
onChange: function (v) { setAttr({ borderRadius: v }); } |
| 204 |
} ), |
| 205 |
el( ToggleControl, { |
| 206 |
label: __( 'Box Shadow', 'blockenberg' ), |
| 207 |
checked: attrs.shadow, |
| 208 |
onChange: function (v) { setAttr({ shadow: v }); }, |
| 209 |
__nextHasNoMarginBottom: true |
| 210 |
} ) |
| 211 |
), |
| 212 |
el( PanelBody, { title: __( 'Author', 'blockenberg' ), initialOpen: false }, |
| 213 |
el( ToggleControl, { |
| 214 |
label: __( 'Show Avatar', 'blockenberg' ), |
| 215 |
checked: attrs.showAvatar, |
| 216 |
onChange: function (v) { setAttr({ showAvatar: v }); }, |
| 217 |
__nextHasNoMarginBottom: true |
| 218 |
} ), |
| 219 |
attrs.showAvatar && el( MediaUploadCheck, null, |
| 220 |
el( MediaUpload, { |
| 221 |
onSelect: function (img) { setAttr({ avatarUrl: img.url, avatarId: img.id }); }, |
| 222 |
allowedTypes: ['image'], |
| 223 |
value: attrs.avatarId, |
| 224 |
render: function ( ref ) { |
| 225 |
return el( Button, { |
| 226 |
onClick: ref.open, |
| 227 |
variant: attrs.avatarUrl ? 'secondary' : 'primary', |
| 228 |
style: { marginBottom: '8px' } |
| 229 |
}, attrs.avatarUrl ? __( 'Change Avatar', 'blockenberg' ) : __( 'Select Avatar', 'blockenberg' ) ); |
| 230 |
} |
| 231 |
} ) |
| 232 |
), |
| 233 |
attrs.showAvatar && el( RangeControl, { |
| 234 |
label: __( 'Avatar Size (px)', 'blockenberg' ), |
| 235 |
value: attrs.avatarSize, min: 32, max: 100, |
| 236 |
onChange: function (v) { setAttr({ avatarSize: v }); } |
| 237 |
} ) |
| 238 |
), |
| 239 |
|
| 240 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 241 |
TC && el(TC, { label: __('Quote Text', 'blockenberg'), value: attrs.quoteTypo || {}, onChange: function(v) { setAttr({ quoteTypo: v }); } }), |
| 242 |
TC && el(TC, { label: __('Author', 'blockenberg'), value: attrs.authorTypo || {}, onChange: function(v) { setAttr({ authorTypo: v }); } }) |
| 243 |
), |
| 244 |
el( PanelBody, { title: __( 'Colors', 'blockenberg' ), initialOpen: false }, |
| 245 |
el( PanelColorSettings, { |
| 246 |
title: __( 'Colors', 'blockenberg' ), |
| 247 |
colorSettings: [ |
| 248 |
{ value: attrs.bgColor, onChange: function(v){setAttr({bgColor:v||''});}, label: __('Background') }, |
| 249 |
{ value: attrs.textColor, onChange: function(v){setAttr({textColor:v||'#222'});}, label: __('Quote Text') }, |
| 250 |
{ value: attrs.markColor, onChange: function(v){setAttr({markColor:v||'#d1c4e9'});}, label: __('Quote Mark') }, |
| 251 |
{ value: attrs.accentColor, onChange: function(v){setAttr({accentColor:v||'#6c3fb5'});}, label: __('Accent Line') } |
| 252 |
] |
| 253 |
} ) |
| 254 |
) |
| 255 |
), |
| 256 |
el( 'blockquote', { |
| 257 |
className: [ |
| 258 |
'bkqp-wrap', |
| 259 |
'bkqp-layout-' + attrs.layout, |
| 260 |
'bkqp-preset-' + attrs.preset, |
| 261 |
attrs.showAccent ? 'bkqp-accent-' + attrs.accentPosition : '', |
| 262 |
attrs.shadow ? 'bkqp-shadow' : '' |
| 263 |
].filter(Boolean).join(' '), |
| 264 |
style: wrapStyle |
| 265 |
}, |
| 266 |
attrs.quoteMarkStyle !== 'none' && el( 'span', { className: 'bkqp-mark', 'aria-hidden': 'true' }, openMark ), |
| 267 |
el( RichText, { |
| 268 |
tagName: 'p', |
| 269 |
className: 'bkqp-text', |
| 270 |
value: attrs.quoteText, |
| 271 |
onChange: function (v) { setAttr({ quoteText: v }); }, |
| 272 |
placeholder: __( 'Your inspiring quote…', 'blockenberg' ) |
| 273 |
} ), |
| 274 |
el( 'footer', { className: 'bkqp-footer' }, |
| 275 |
attrs.showAvatar && attrs.avatarUrl && el( 'img', { |
| 276 |
className: 'bkqp-avatar', |
| 277 |
src: attrs.avatarUrl, |
| 278 |
alt: attrs.authorName |
| 279 |
} ), |
| 280 |
el( 'div', { className: 'bkqp-cite' }, |
| 281 |
el( RichText, { |
| 282 |
tagName: 'cite', |
| 283 |
className: 'bkqp-author', |
| 284 |
value: attrs.authorName, |
| 285 |
onChange: function (v) { setAttr({ authorName: v }); }, |
| 286 |
placeholder: __( 'Author Name', 'blockenberg' ) |
| 287 |
} ), |
| 288 |
el( RichText, { |
| 289 |
tagName: 'small', |
| 290 |
className: 'bkqp-role', |
| 291 |
value: attrs.authorRole, |
| 292 |
onChange: function (v) { setAttr({ authorRole: v }); }, |
| 293 |
placeholder: __( 'Title / Role', 'blockenberg' ) |
| 294 |
} ) |
| 295 |
) |
| 296 |
) |
| 297 |
) |
| 298 |
); |
| 299 |
}, |
| 300 |
save: function ( props ) { |
| 301 |
var attrs = props.attributes; |
| 302 |
var mark = QUOTE_MARKS[ attrs.quoteMarkStyle ] || QUOTE_MARKS.curved; |
| 303 |
var openMark = mark ? mark[0] : ''; |
| 304 |
return el( 'blockquote', { |
| 305 |
className: [ |
| 306 |
'bkqp-wrap', |
| 307 |
'bkqp-layout-' + attrs.layout, |
| 308 |
'bkqp-preset-' + attrs.preset, |
| 309 |
attrs.showAccent ? 'bkqp-accent-' + attrs.accentPosition : '', |
| 310 |
attrs.shadow ? 'bkqp-shadow' : '' |
| 311 |
].filter(Boolean).join(' '), |
| 312 |
style: (function () { |
| 313 |
var _tv = getTypoCssVars(); |
| 314 |
var s = { |
| 315 |
'--bkqp-bg': attrs.bgColor || 'transparent', |
| 316 |
'--bkqp-text': attrs.textColor, |
| 317 |
'--bkqp-mark': attrs.markColor, |
| 318 |
'--bkqp-accent': attrs.accentColor, |
| 319 |
'--bkqp-accentW': attrs.accentWidth + 'px', |
| 320 |
'--bkqp-pv': attrs.paddingV + 'px', |
| 321 |
'--bkqp-ph': attrs.paddingH + 'px', |
| 322 |
'--bkqp-radius': attrs.borderRadius + 'px', |
| 323 |
'--bkqp-avatarSz': attrs.avatarSize + 'px' |
| 324 |
}; |
| 325 |
if (_tv) { |
| 326 |
Object.assign(s, _tv(attrs.quoteTypo || {}, '--bkqp-qt-')); |
| 327 |
Object.assign(s, _tv(attrs.authorTypo || {}, '--bkqp-au-')); |
| 328 |
} |
| 329 |
return s; |
| 330 |
})() |
| 331 |
}, |
| 332 |
attrs.quoteMarkStyle !== 'none' && el( 'span', { className: 'bkqp-mark', 'aria-hidden': 'true' }, openMark ), |
| 333 |
el( RichText.Content, { tagName: 'p', className: 'bkqp-text', value: attrs.quoteText } ), |
| 334 |
el( 'footer', { className: 'bkqp-footer' }, |
| 335 |
attrs.showAvatar && attrs.avatarUrl && el( 'img', { |
| 336 |
className: 'bkqp-avatar', |
| 337 |
src: attrs.avatarUrl, |
| 338 |
alt: attrs.authorName, |
| 339 |
loading: 'lazy' |
| 340 |
} ), |
| 341 |
el( 'div', { className: 'bkqp-cite' }, |
| 342 |
el( RichText.Content, { tagName: 'cite', className: 'bkqp-author', value: attrs.authorName } ), |
| 343 |
el( RichText.Content, { tagName: 'small', className: 'bkqp-role', value: attrs.authorRole } ) |
| 344 |
) |
| 345 |
) |
| 346 |
); |
| 347 |
} |
| 348 |
} ); |
| 349 |
|
| 350 |
} )(); |
| 351 |
|